Skip to content

Commit

Permalink
Merge pull request #337 from Ladicek/better-magic-error
Browse files Browse the repository at this point in the history
improve error message when verifying magic bytes of the input
  • Loading branch information
Ladicek authored Oct 18, 2023
2 parents 310da1e + 618acc6 commit 468cd08
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/org/jboss/jandex/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2085,9 +2085,15 @@ private boolean isJDK11OrNewer(DataInputStream stream) throws IOException {
}

private void verifyMagic(DataInputStream stream) throws IOException {
final int magic = stream.readInt();
final int magic;
try {
magic = stream.readInt();
} catch (EOFException e) {
throw new EOFException("Input is not a valid class file; must begin with a 4-byte integer 0xCAFEBABE");
}
if (magic != 0xCA_FE_BA_BE) {
throw new IOException("Invalid Magic");
throw new IOException("Input is not a valid class file; must begin with a 4-byte integer 0xCAFEBABE, "
+ "but seen 0x" + Integer.toHexString(magic).toUpperCase());
}
}

Expand Down

0 comments on commit 468cd08

Please sign in to comment.