Skip to content

Commit

Permalink
Fix class file version detection
Browse files Browse the repository at this point in the history
we are forcing 1.8 class file version when it's below, but we
are checking against the full version while we need to check against
the major version only
  • Loading branch information
jpbempel committed Dec 5, 2024
1 parent 5b58772 commit fdca440
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private byte[] writeClassFile(
ClassLoader loader,
String classFilePath,
ClassNode classNode) {
if (classNode.version < Opcodes.V1_8) {
if ((classNode.version & 0xFF) < Opcodes.V1_8) {
// Class file version must be at least 1.8 (52)
classNode.version = Opcodes.V1_8;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import java.lang.reflect.Modifier;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -211,6 +212,24 @@ public void veryOldClassFile() throws Exception {
assertOneSnapshot(listener);
}

@Test
public void oldClass1_1() throws Exception {
final String CLASS_NAME = "org.apache.commons.lang.BooleanUtils"; // compiled with jdk 1.1
TestSnapshotListener listener = installSingleProbe(CLASS_NAME, "toBoolean", null);
when(config.isDebuggerVerifyByteCode()).thenReturn(true);
Class<?> testClass =
loadClass(
CLASS_NAME,
Paths.get(
CapturedSnapshotTest.class
.getResource("/classfiles/BooleanUtils.classfile")
.toURI())
.toString());
boolean result = Reflect.onClass(testClass).call("toBoolean", Boolean.TRUE).get();
assertTrue(result);
assertOneSnapshot(listener);
}

@Test
public void oldJavacBug() throws Exception {
final String CLASS_NAME = "com.datadog.debugger.classfiles.JavacBug"; // compiled with jdk 1.6
Expand Down
Binary file not shown.

0 comments on commit fdca440

Please sign in to comment.