diff --git a/Text/ProtocolBuffers/ProtoCompile/MakeReflections.hs b/Text/ProtocolBuffers/ProtoCompile/MakeReflections.hs
--- a/Text/ProtocolBuffers/ProtoCompile/MakeReflections.hs
+++ b/Text/ProtocolBuffers/ProtoCompile/MakeReflections.hs
@@ -211,7 +211,7 @@
                    TYPE_STRING  -> Just parseDefString
                    _            -> Just parseDefInteger
          case todo (utf8 bs) of
-           Nothing -> error $ "Could not parse as type "++ show t ++"the default value "++ show mayRawDef ++" for field "++show f
+           Nothing -> error $ "Could not parse as type "++ show t ++" the default value (raw) is "++ show mayRawDef ++" for field "++show f
            Just value -> return value
 
 --- From here down is code used to parse the format of the default values in the .proto files
@@ -244,8 +244,8 @@
 parseDefInteger :: ByteString -> Maybe HsDefault
 parseDefInteger bs = fmap HsDef'Integer . mayRead checkSign . U.toString $ bs
     where checkSign = readSigned' checkBase
-          checkBase ('0':'x':xs) = readHex xs
-          checkBase ('0':xs) = readOct xs
+          checkBase ('0':'x':xs@(_:_)) = readHex xs
+          checkBase ('0':xs@(_:_)) = readOct xs
           checkBase xs = readDec xs
 
 parseDefBool :: ByteString -> Maybe HsDefault
diff --git a/Text/ProtocolBuffers/ProtoCompile/Resolve.hs b/Text/ProtocolBuffers/ProtoCompile/Resolve.hs
--- a/Text/ProtocolBuffers/ProtoCompile/Resolve.hs
+++ b/Text/ProtocolBuffers/ProtoCompile/Resolve.hs
@@ -66,7 +66,7 @@
 import Data.Char
 import Data.Ratio
 import Data.Ix(inRange)
-import Data.List(foldl',stripPrefix,lookup,isPrefixOf)
+import Data.List(foldl',stripPrefix,lookup,isPrefixOf,isSuffixOf)
 import Data.Map(Map)
 import Data.Maybe(mapMaybe)
 import Data.Monoid(Monoid(..))
@@ -108,6 +108,40 @@
 getJust s ma@Nothing = throw $ "Impossible? Expected Just of type "++show (typeOf ma)++" but got nothing:\n"++indent s
 getJust _s (Just a) = return a
 
+defaultPackageName :: Utf8
+defaultPackageName = Utf8 (LC.pack "proto")
+
+getPackage :: D.FileDescriptorProto -> Utf8
+getPackage fdp = case D.FileDescriptorProto.package fdp of
+                   Just a -> a
+                   Nothing -> case D.FileDescriptorProto.name fdp of
+                                Nothing -> defaultPackageName
+                                Just filename -> case convertFileToPackage filename of
+                                                   Nothing -> defaultPackageName
+                                                   Just name -> name
+
+-- | 'convertFileToPackage' mimics what I observe protoc --java_out do to convert the file name to a
+-- class name.
+convertFileToPackage :: Utf8 -> Maybe Utf8
+convertFileToPackage filename =
+  let full = toString filename
+      suffix = ".proto"
+      noproto = if suffix `isSuffixOf` full then take (length full - length suffix) full else full
+      convert :: Bool -> String -> String
+      convert _ [] = []
+      convert toUp (x:xs) | inRange ('a','z') x = if toUp
+                                                    then toUpper x : convert False xs
+                                                    else x : convert False xs
+                          | inRange ('A','Z') x = x : convert False xs
+                          | inRange ('0','9') x = x : convert True xs
+                          | '_' == x = x : convert True xs
+                          | otherwise = convert True xs
+      converted = convert True noproto
+      leading = case converted of
+                  (x:_) | inRange ('0','9') x -> "proto_" ++ converted
+                  _ -> converted
+  in if null leading then Nothing else (Just (fromString leading))
+
 -- This adds a leading dot if the input is non-empty
 joinDot :: [IName String] -> FIName String
 joinDot [] = err $ "joinDot on an empty list of IName!"
@@ -439,14 +473,13 @@
 --  makeOne :: D.FileDescriptorProto -> WriterT [(FIName Utf8,ProtoName)] (Either ErrStr) ()
   makeOne fdp = do
     -- Create 'template' :: ProtoName using "Text.ProtocolBuffers.Identifiers"
-    rawPackage <- getJust "makeNameMap.makeOne: D.FileDescriptorProto.package"
-                  (D.FileDescriptorProto.package fdp)
+    let rawPackage = getPackage fdp
     lift (checkDIUtf8 rawPackage) -- guard-like effect
     let packageName = difi (DIName rawPackage)
     rawParent <- getJust "makeNameMap.makeOne: " . msum $
         [ D.FileOptions.java_outer_classname =<< (D.FileDescriptorProto.options fdp)
         , D.FileOptions.java_package =<< (D.FileDescriptorProto.options fdp)
-        , D.FileDescriptorProto.package fdp]
+        , Just (getPackage fdp)]
     diParent <- getJust ("makeNameMap.makeOne: invalid character in: "++show rawParent)
                   (validDI rawParent)
     let hParent = map (mangle :: IName Utf8 -> MName String) . splitDI $ diParent
@@ -1061,7 +1094,7 @@
             parsed'fdp <- either (loadFailed toRead . show) return $
                           (parseProto (unCanonFP relpath) protoContents)
             packageName <- either (loadFailed toRead . show) (return . map iToString . snd) $
-                           (checkDIUtf8 =<< getJust "makeTopLevel.packageName: you need a pacakge declaration in your proto file" (D.FileDescriptorProto.package parsed'fdp))
+                           (checkDIUtf8 (getPackage parsed'fdp)) -- =<< getJust "makeTopLevel.packageName: you need a pacakge declaration in your proto file" (D.FileDescriptorProto.package parsed'fdp))
             let parents = Set.insert file parentsIn
                 importList = map (fpCanonToLocal . CanonFP . toString) . F.toList . D.FileDescriptorProto.dependency $ parsed'fdp
             imports <- mapM (fmap getTL . load parents) importList
diff --git a/hprotoc.cabal b/hprotoc.cabal
--- a/hprotoc.cabal
+++ b/hprotoc.cabal
@@ -1,5 +1,5 @@
 name:           hprotoc
-version:        1.5.0
+version:        1.5.1
 cabal-version:  >= 1.6
 build-type:     Simple
 license:        BSD3
