Skip to content

Commit

Permalink
Fix method checks to also look into superclasses if method was overri…
Browse files Browse the repository at this point in the history
…dden.

Closes #100
  • Loading branch information
uschindler committed May 22, 2016
1 parent 95d9d55 commit 49d3a7c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/de/thetaphi/forbiddenapis/ClassScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,19 +340,30 @@ private String checkMethodAccess(String owner, Method method) {
if (violation != null) {
return violation;
}
return checkMethodAccessRecursion(owner, method);
}

private String checkMethodAccessRecursion(String owner, Method method) {
final String printout = forbiddenMethods.get(owner + '\000' + method);
if (printout != null) {
return "Forbidden method invocation: " + printout;
}
final ClassSignature c = lookup.lookupRelatedClass(owner);
if (c != null && !c.methods.contains(method)) {
if (c.superName != null && (violation = checkMethodAccess(c.superName, method)) != null) {
if (c != null) {
String violation;
if (c.methods.contains(method)) {
violation = checkClassUse(owner, "class/interface");
if (violation != null) {
return violation;
}
}
if (c.superName != null && (violation = checkMethodAccessRecursion(c.superName, method)) != null) {
return violation;
}
// JVM spec says: interfaces after superclasses
if (c.interfaces != null) {
for (String intf : c.interfaces) {
if (intf != null && (violation = checkMethodAccess(intf, method)) != null) {
if (intf != null && (violation = checkMethodAccessRecursion(intf, method)) != null) {
return violation;
}
}
Expand All @@ -371,6 +382,7 @@ private String checkFieldAccess(String owner, String field) {
return "Forbidden field access: " + printout;
}
final ClassSignature c = lookup.lookupRelatedClass(owner);
// if we have seen the field already, no need to look into superclasses (fields cannot override)
if (c != null && !c.fields.contains(field)) {
if (c.interfaces != null) {
for (String intf : c.interfaces) {
Expand Down

0 comments on commit 49d3a7c

Please sign in to comment.