Skip to content

Commit 27641db

Browse files
authored
Fix symbol extraction for interface static method (#9597)
not all methods with code in interface are default, only the non-static ones
1 parent e992b65 commit 27641db

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/SymbolExtractor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ private static Collection<String> extractMethodModifiers(
237237
"Invalid access modifiers method[" + methodNode.name + methodNode.desc + "]: " + bit);
238238
}
239239
}
240-
// if class is an interface && method as code this is a default method
241-
if ((classNode.access & Opcodes.ACC_INTERFACE) > 0 && methodNode.instructions.size() > 0) {
240+
// if class is an interface && method has code && non-static this is a default method
241+
if ((classNode.access & Opcodes.ACC_INTERFACE) > 0
242+
&& methodNode.instructions.size() > 0
243+
&& (methodNode.access & Opcodes.ACC_STATIC) == 0) {
242244
results.add("default");
243245
}
244246
return results;

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/SymbolExtractionTransformerTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,14 @@ public void symbolExtraction14() throws IOException, URISyntaxException {
829829
null,
830830
null,
831831
Void.TYPE.getTypeName());
832+
Scope m4MethodScope = i1ClassScope.getScopes().get(1);
833+
assertLangSpecifics(
834+
m4MethodScope.getLanguageSpecifics(),
835+
asList("public", "static"),
836+
null,
837+
null,
838+
null,
839+
String.class.getTypeName());
832840
Scope myEnumClassScope = symbolSinkMock.jarScopes.get(3).getScopes().get(0);
833841
assertLangSpecifics(
834842
myEnumClassScope.getLanguageSpecifics(),

dd-java-agent/agent-debugger/src/test/resources/com/datadog/debugger/symboltest/SymbolExtraction14.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ private strictfp synchronized final String m2(String... strVarArgs) {
2323

2424
interface I1 {
2525
default void m3(){}
26+
static String m4(String arg){
27+
return arg;
28+
}
2629
}
2730

2831
interface I2 {

0 commit comments

Comments
 (0)