Skip to content

Commit 6246ef3

Browse files
committed
Bugfix: Only construct phantom fields at the top of the class hierarchy or when reaching a phantom class
1 parent efedc25 commit 6246ef3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/soot/AbstractSootFieldRef.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,22 @@ private SootField resolve(StringBuffer trace) {
8888
while(true) {
8989
if(trace != null) trace.append(
9090
"Looking in "+cl+" which has fields "+cl.getFields()+"\n" );
91+
92+
// Check whether we have the field in the current class
9193
if( cl.declaresField(name, type) ) {
9294
return checkStatic(cl.getField(name, type));
9395
}
94-
95-
if(Scene.v().allowsPhantomRefs() && (cl.isPhantom() || Options.v().ignore_resolution_errors()))
96-
{
96+
97+
// If we have a phantom class, we directly construct a phantom field
98+
// in it and don't care about superclasses.
99+
if (Scene.v().allowsPhantomRefs() && cl.isPhantom()) {
97100
SootField f = new SootField(name, type, isStatic()?Modifier.STATIC:0);
98101
f.setPhantom(true);
99102
cl.addField(f);
100103
return f;
101-
} else {
104+
}
105+
else {
106+
// Since this class is not phantom, we look at its interfaces
102107
LinkedList<SootClass> queue = new LinkedList<SootClass>();
103108
queue.addAll( cl.getInterfaces() );
104109
while( !queue.isEmpty() ) {
@@ -110,6 +115,9 @@ private SootField resolve(StringBuffer trace) {
110115
}
111116
queue.addAll( iface.getInterfaces() );
112117
}
118+
119+
// If we have not found a suitable field in the current class,
120+
// try the superclass
113121
if( cl.hasSuperclass() ) cl = cl.getSuperclass();
114122
else break;
115123
}

0 commit comments

Comments
 (0)