Skip to content

Commit 479d312

Browse files
committed
Fix inner class fields in Soot and SootUp
1 parent 2944c26 commit 479d312

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

boomerangPDS/src/test/java/test/options/OptionsTestingFramework.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import boomerang.results.BackwardBoomerangResults;
2323
import boomerang.scope.AllocVal;
2424
import boomerang.scope.DataFlowScope;
25+
import boomerang.scope.DeclaredMethod;
2526
import boomerang.scope.FrameworkScope;
27+
import boomerang.scope.Method;
2628
import boomerang.scope.Val;
2729
import boomerang.utils.MethodWrapper;
2830
import java.util.Arrays;
@@ -45,11 +47,7 @@ public void analyze(
4547
BoomerangOptions options,
4648
String[] expectedAllocSites) {
4749
analyze(
48-
targetClassName,
49-
targetMethodName,
50-
options,
51-
DataFlowScope.EXCLUDE_PHANTOM_CLASSES,
52-
expectedAllocSites);
50+
targetClassName, targetMethodName, options, new OptionsDataFlowScope(), expectedAllocSites);
5351
}
5452

5553
public void analyze(
@@ -87,8 +85,8 @@ public void analyze(
8785

8886
if (allocVal.isStringConstant()) {
8987
actualAllocSiteStrings.add(allocVal.getStringValue());
90-
} else {
91-
actualAllocSiteStrings.add(allocVal.toString());
88+
} else if (allocVal.isIntConstant()) {
89+
actualAllocSiteStrings.add(String.valueOf(allocVal.getIntValue()));
9290
}
9391
}
9492

@@ -118,4 +116,27 @@ private Collection<AllocVal> computeAllocSites(
118116

119117
return allocSites;
120118
}
119+
120+
/**
121+
* For some reason, Soot does not consider the Object and String class as phantom, i.e. the
122+
* analysis tries to find data flows within these classes. Hence, we have to exclude them
123+
* manually.
124+
*/
125+
private static class OptionsDataFlowScope implements DataFlowScope {
126+
127+
private final Collection<String> excludedClasses =
128+
Set.of(Object.class.getName(), String.class.getName());
129+
130+
@Override
131+
public boolean isExcluded(DeclaredMethod method) {
132+
return method.getDeclaringClass().isPhantom()
133+
|| excludedClasses.contains(method.getDeclaringClass().getFullyQualifiedName());
134+
}
135+
136+
@Override
137+
public boolean isExcluded(Method method) {
138+
return method.getDeclaringClass().isPhantom()
139+
|| excludedClasses.contains(method.getDeclaringClass().getFullyQualifiedName());
140+
}
141+
}
121142
}

boomerangPDS/src/test/java/test/options/boomerang/ArrayStrategyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void indexSensitiveTest() {
3535

3636
@Test
3737
@TestOptions(
38-
expectedAllocSites = {"new java.lang.String[]", "Hello", "there"},
38+
expectedAllocSites = {"Hello", "there"},
3939
arrayStrategy = Strategies.ArrayStrategy.INDEX_INSENSITIVE)
4040
public void indexInsensitiveTest() {
4141
String[] s = new String[] {"Hello", "there"};

boomerangScope-Soot/src/main/java/boomerang/scope/soot/jimple/JimpleField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public String getName() {
3737

3838
@Override
3939
public boolean isInnerClassField() {
40-
return this.delegate.name().contains("$");
40+
return delegate.declaringClass().getName().contains("$");
4141
}
4242

4343
@Override

boomerangScope-SootUp/src/main/java/boomerang/scope/sootup/jimple/JimpleUpField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public String getName() {
3737

3838
@Override
3939
public boolean isInnerClassField() {
40-
return delegate.getName().contains("$");
40+
return delegate.getDeclClassType().getFullyQualifiedName().contains("$");
4141
}
4242

4343
@Override

testCore/src/main/java/test/TestingFramework.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class TestingFramework {
3636
private static final String OPAL = "opal";
3737

3838
/** This variable may be changed to run the tests locally */
39-
private static final String DEFAULT_FRAMEWORK = OPAL;
39+
private static final String DEFAULT_FRAMEWORK = SOOT;
4040

4141
private final TestSetup testSetup;
4242
private final Collection<String> includedClasses;

0 commit comments

Comments
 (0)