Skip to content

Commit

Permalink
Also look into superclasses now, this is correct way to handle it
Browse files Browse the repository at this point in the history
  • Loading branch information
uschindler committed Nov 6, 2023
1 parent 5de7f4e commit 910851d
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/main/java/de/thetaphi/forbiddenapis/ClassScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,6 @@ private String checkMethodAccess(String owner, final Method method, final boolea
if (violation != null) {
return violation;
}
if (!callIsVirtual) {
return null; // don't look into superclasses or interfaces for static or special calls (like ctors)
}
final ClassMetadata c = lookup.lookupRelatedClass(owner, owner);
if (c == null) {
return null;
Expand All @@ -413,8 +410,10 @@ public String visit(ClassMetadata c, String origName, boolean isInterfaceOfAnces
if (!c.methods.contains(lookupMethod)) {
return null;
}
// is we have a virtual call, look into superclasses, otherwise stop:
final String notFoundRet = callIsVirtual ? null : AncestorVisitor.STOP;
if (previousInRuntime && c.isNonPortableRuntime) {
return null; // something inside the JVM is extending internal class/interface
return notFoundRet; // something inside the JVM is extending internal class/interface
}
String violation = forbiddenSignatures.checkMethod(c.className, lookupMethod);
if (violation != null) {
Expand All @@ -427,7 +426,7 @@ public String visit(ClassMetadata c, String origName, boolean isInterfaceOfAnces
return violation;
}
}
return null;
return notFoundRet;
}
}, true, false /* JVM spec says: interfaces after superclasses */);
}
Expand All @@ -442,9 +441,6 @@ private String checkFieldAccess(String owner, final String field, final boolean
if (violation != null) {
return violation;
}
if (!callIsVirtual) {
return null; // don't look into superclasses or interfaces for static field lookups
}
final ClassMetadata c = lookup.lookupRelatedClass(owner, owner);
if (c == null) {
return null;
Expand All @@ -455,9 +451,10 @@ public String visit(ClassMetadata c, String origName, boolean isInterfaceOfAnces
if (!c.fields.contains(field)) {
return null;
}
// we found the field: from now on we use STOP to exit, because fields are not virtual!
// is we have a virtual call, look into superclasses, otherwise stop:
final String notFoundRet = callIsVirtual ? null : AncestorVisitor.STOP;
if (previousInRuntime && c.isNonPortableRuntime) {
return STOP; // something inside the JVM is extending internal class/interface
return notFoundRet; // something inside the JVM is extending internal class/interface
}
String violation = forbiddenSignatures.checkField(c.className, field);
if (violation != null) {
Expand All @@ -470,8 +467,7 @@ public String visit(ClassMetadata c, String origName, boolean isInterfaceOfAnces
return violation;
}
}
// we found the field and as those are not virtual, there is no need to go up in class hierarchy:
return STOP;
return notFoundRet;
}
}, true, true /* JVM spec says: superclasses after interfaces */);
}
Expand Down

0 comments on commit 910851d

Please sign in to comment.