Commit 0e3b9cee authored by Delphine Martin's avatar Delphine Martin Committed by android-build-merger
Browse files

Merge "Add better error message for unsupported classfile"

am: d317cc3a

* commit 'd317cc3a':
  Add better error message for unsupported classfile
parents a7cfa750 d317cc3a
......@@ -415,21 +415,29 @@ public class DirectClassFile implements ClassFile {
}
/**
* Sees if the .class file header magic/version are within
* range.
* Sees if the .class file header magic has the good value.
*
* @param magic the value of a classfile "magic" field
* @return true if the magic is valid
*/
private boolean isGoodMagic(int magic) {
return magic == CLASS_FILE_MAGIC;
}
/**
* Sees if the .class file header version are within
* range.
*
* @param minorVersion the value of a classfile "minor_version" field
* @param majorVersion the value of a classfile "major_version" field
* @return true iff the parameters are valid and within range
* @return true if the parameters are valid and within range
*/
private boolean isGoodVersion(int magic, int minorVersion,
int majorVersion) {
private boolean isGoodVersion(int minorVersion, int majorVersion) {
/* Valid version ranges are typically of the form
* "A.0 through B.C inclusive" where A <= B and C >= 0,
* which is why we don't have a CLASS_FILE_MIN_MINOR_VERSION.
*/
if (magic == CLASS_FILE_MAGIC && minorVersion >= 0) {
if (minorVersion >= 0) {
/* Check against max first to handle the case where
* MIN_MAJOR == MAX_MAJOR.
*/
......@@ -467,13 +475,14 @@ public class DirectClassFile implements ClassFile {
/* Make sure that this looks like a valid class file with a
* version that we can handle.
*/
if (!isGoodVersion(getMagic0(), getMinorVersion0(),
getMajorVersion0())) {
throw new ParseException("bad class file magic (" +
Hex.u4(getMagic0()) +
") or version (" +
Hex.u2(getMajorVersion0()) + "." +
Hex.u2(getMinorVersion0()) + ")");
if (!isGoodMagic(getMagic0())) {
throw new ParseException("bad class file magic (" + Hex.u4(getMagic0()) + ")");
}
if (!isGoodVersion(getMinorVersion0(), getMajorVersion0())) {
throw new ParseException("unsupported class file version " +
getMajorVersion0() + "." +
getMinorVersion0());
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment