stevedlawrence commented on a change in pull request #641:
URL: https://github.com/apache/daffodil/pull/641#discussion_r714035211
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/compiler/Compiler.scala
##########
@@ -283,7 +284,31 @@ class Compiler private (var validateDFDLSchemas: Boolean,
def reload(savedParser: java.nio.channels.ReadableByteChannel):
DFDL.DataProcessor = {
try {
- val objInput = new ObjectInputStream(new
GZIPInputStream(Channels.newInputStream(savedParser))) {
+ val is = Channels.newInputStream(savedParser)
+
+ // Read the magic number and version information for this saved parser
+ // directly from the input stream. That information is not compressed or
+ // serialized
+ val magicNumber = "DAFFODIL "
+ magicNumber.foreach { c =>
+ if (is.read() != c.toInt) throw new InvalidParserException("The saved
parser is only compatible with an older version of Daffodil")
+ }
+
+ val sb = new StringBuilder()
+ var byte: Int = -1
+ while ({ byte = is.read(); byte > 0 }) {
+ sb.append(byte.toChar)
+ }
+ if (byte == -1) {
+ throw new InvalidParserException("The saved parser file is not the
correct format")
Review comment:
I guess I was avoiding giving too much information that doesn't really
help anything but to confuse a user. No one should be manually modifying these
files, so telling someone specifically what is wrong doesn't really help them
fix the problem. If anything, they'll wonder what it means to be missing a
prefix and try to fix that problem. The problem is really that the file was
corrupted or something (we don't really know). Maybe instead of "not correct
format' we sould say "looks to be corrupted"? Though, I'm not sure if that
gives any extra information aside from guessing what cause the issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]