diff options
| author | Delphine Martin <delphinemartin@google.com> | 2016-02-05 15:21:00 +0100 |
|---|---|---|
| committer | Delphine Martin <delphinemartin@google.com> | 2016-02-05 15:29:48 +0100 |
| commit | 45fd158052a5ebfc57e7a063c6990da5ae019aac (patch) | |
| tree | 5be4541bcde6c321ba7cdf6e638aa4cd3afb6baa | |
| parent | 47d5a85f8b82542e3f1ce4ee29c48ec17d70589f (diff) | |
| download | android_dalvik-45fd158052a5ebfc57e7a063c6990da5ae019aac.tar.gz android_dalvik-45fd158052a5ebfc57e7a063c6990da5ae019aac.tar.bz2 android_dalvik-45fd158052a5ebfc57e7a063c6990da5ae019aac.zip | |
Add better error message for unsupported classfile
- There are now 2 differents messages for bad magic number and
unsupported version
- The version number is printed in decimal instead of hexadecimal.
Bug: 25075831
Change-Id: I37227c65779c432d6d699a27c54d97766f8ff550
| -rw-r--r-- | dx/src/com/android/dx/cf/direct/DirectClassFile.java | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/dx/src/com/android/dx/cf/direct/DirectClassFile.java b/dx/src/com/android/dx/cf/direct/DirectClassFile.java index f908547cb..089e43a47 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 @@ 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()); } } |
