-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade ASM to 7.1 #851
Upgrade ASM to 7.1 #851
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally we have an change log entry for this. Should we also have one for a minor version upgrade?
@marchof this is because you picked PR which is still in "implementation" 😆 btw hard to predict url for changelog before creation of PR 😉 |
@@ -238,7 +236,7 @@ public static void push(final MethodVisitor mv, final int value) { | |||
*/ | |||
public static ClassReader classReaderFor(final byte[] b) { | |||
final byte[] originalVersion = new byte[] { b[4], b[5], b[6], b[7] }; | |||
if (getVersionMajor(b) == Opcodes.V12 + 1) { | |||
if (b[6] == 0x00 && b[7] == 0x39) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic number? The intend was more clear with Opcodes.V12 + 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof inlining of former implementation of getVersionMajor
into this method results in
final int majorVersion = (short) (((b[MAJOR_VERSION_INDEX] & 0xFF) << 8)
| (b[MAJOR_VERSION_INDEX + 1] & 0xFF));
if (majorVersion == Opcodes.V12 + 1)
which IMO contains far more magic and far less readable than
if (b[6] == 0x00 && b[7] == 0x39)
Can also add comment.
Readable and non-magical alternative
final int majorVersion = java.nio.ByteBuffer.wrap(b)
.order(java.nio.ByteOrder.BIG_ENDIAN).getShort(6);
looks like a bit of overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW numbers 6
, 7
and 0x39
are even shown in https://en.wikipedia.org/wiki/Java_class_file 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So why inlining? If we keep the previous method (in addition to the new Reader version) we have testable and readable code ;)
@Godin If you like we can merge as is and check in a separate PR how we can streamline version reading/writing. Ok? |
@Godin What about requesting a new public API |
@Godin With explicit methods to read versions the code becomes way more understandable:
|
Feel free to ask them 😉 😇 Speaking about understandability, testability and magic 🔮 - actually implementation of jacoco/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java Lines 170 to 173 in 6cd3f0b
is incorrect, as well as
because according to JVMS For example let's consider
which fails
IMO such mistake is impossible in case of proposed exact comparison of bytes
😉 However proposed implementation of jacoco/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java Lines 168 to 171 in c7e2176
has the same mistake because of Both come from the fact that ASM itself uses same signed Moreover jacoco/org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java Lines 182 to 185 in 6cd3f0b
is also incorrect and will fail / require change earlier - in about 122 years 😈
Morever similarly to #851 (comment) about I added correct implementations of |
@Godin Thanks for fixing this right away!
Ok, we document this as know limitation -- along with > 32 dimensional arrays 🤣 |
Fixes #839