Merge "Add better error message for unsupported classfile"
diff --git a/dx/src/com/android/dx/cf/direct/DirectClassFile.java b/dx/src/com/android/dx/cf/direct/DirectClassFile.java
index f908547..089e43a 100644
--- a/dx/src/com/android/dx/cf/direct/DirectClassFile.java
+++ b/dx/src/com/android/dx/cf/direct/DirectClassFile.java
@@ -415,21 +415,29 @@
}
/**
- * 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 @@
/* 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());
}
}