Skip to content

Commit fdca440

Browse files
committed
Fix class file version detection
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
1 parent 5b58772 commit fdca440

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private byte[] writeClassFile(
422422
ClassLoader loader,
423423
String classFilePath,
424424
ClassNode classNode) {
425-
if (classNode.version < Opcodes.V1_8) {
425+
if ((classNode.version & 0xFF) < Opcodes.V1_8) {
426426
// Class file version must be at least 1.8 (52)
427427
classNode.version = Opcodes.V1_8;
428428
}

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import java.lang.reflect.Modifier;
6767
import java.net.URISyntaxException;
6868
import java.net.URL;
69+
import java.nio.file.Paths;
6970
import java.util.ArrayList;
7071
import java.util.Arrays;
7172
import java.util.Collections;
@@ -211,6 +212,24 @@ public void veryOldClassFile() throws Exception {
211212
assertOneSnapshot(listener);
212213
}
213214

215+
@Test
216+
public void oldClass1_1() throws Exception {
217+
final String CLASS_NAME = "org.apache.commons.lang.BooleanUtils"; // compiled with jdk 1.1
218+
TestSnapshotListener listener = installSingleProbe(CLASS_NAME, "toBoolean", null);
219+
when(config.isDebuggerVerifyByteCode()).thenReturn(true);
220+
Class<?> testClass =
221+
loadClass(
222+
CLASS_NAME,
223+
Paths.get(
224+
CapturedSnapshotTest.class
225+
.getResource("/classfiles/BooleanUtils.classfile")
226+
.toURI())
227+
.toString());
228+
boolean result = Reflect.onClass(testClass).call("toBoolean", Boolean.TRUE).get();
229+
assertTrue(result);
230+
assertOneSnapshot(listener);
231+
}
232+
214233
@Test
215234
public void oldJavacBug() throws Exception {
216235
final String CLASS_NAME = "com.datadog.debugger.classfiles.JavacBug"; // compiled with jdk 1.6
Binary file not shown.

0 commit comments

Comments
 (0)