Fix 2 Eclipse warnings about useless instanceof checks

Effectively these two checks could only be false if the instance being
tested were null.  So we replace the instanceof checks with null
checks.  Sometimes that, in turn, makes other surrounding code
simpler.  In the case of ApplicationLoaderFilter.test, for example,
a whole conditional case ("o instanceof LocalPointerKey") becomes
statically impossible.  That seems a bit strange to me, but that's
what the code was effectively doing.
This commit is contained in:
Ben Liblit 2017-03-18 00:14:53 -05:00
parent 934f8f524f
commit 94fcc3966f
2 changed files with 3 additions and 9 deletions

View File

@ -198,15 +198,9 @@ public class PDFCallGraph {
private static class ApplicationLoaderFilter extends Predicate<CGNode> {
@Override public boolean test(CGNode o) {
if (o instanceof CGNode) {
CGNode n = (CGNode) o;
return n.getMethod().getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Application);
} else if (o instanceof LocalPointerKey) {
LocalPointerKey l = (LocalPointerKey) o;
return test(l.getNode());
} else {
if (o == null)
return false;
}
return o.getMethod().getDeclaringClass().getClassLoader().getReference().equals(ClassLoaderReference.Application);
}
}
}

View File

@ -261,7 +261,7 @@ public class DefaultFixedPointSystem<T extends IVariable<?>> implements IFixedPo
public Iterator<T> getVariables() {
return new FilterIterator<>(graph.iterator(), new Predicate<T>() {
@Override public boolean test(T x) {
return x instanceof IVariable;
return x != null;
}
});
}