Skip to content

Commit

Permalink
Fix issue #26: Also look at superclasses and interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
uschindler committed Apr 16, 2014
1 parent b1bc440 commit eaf9785
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/main/java/de/thetaphi/forbiddenapis/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,11 @@ boolean checkType(Type type) {
while (type != null) {
switch (type.getSort()) {
case Type.OBJECT:
// don't check superclasses (TODO: investigate):
return checkClassUse(type.getInternalName());
if (checkClassUse(type.getInternalName())) {
return true;
}
final ClassSignatureLookup c = lookupRelatedClass(type.getInternalName());
return (c != null && checkClassDefinition(c.superName, c.interfaces));
case Type.ARRAY:
type = type.getElementType();
break;
Expand Down
Binary file modified src/test/antunit/Java5ClassReferences.class
Binary file not shown.
7 changes: 7 additions & 0 deletions src/test/antunit/Java5ClassReferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/* The binary class file is packaged together with the source distribution.
*/

import java.util.*;

class Java5ClassReferences {
static Integer[][] test() {
Integer.class.getName();
Expand All @@ -28,4 +30,9 @@ static Integer[][] test() {

private Integer field1;
private final Integer[] field2 = null;

// we forbid the superclass or interface, but concrete instance is used:
public List<?> list1;
public ArrayList<?> list2;
public HashSet<?> set1;
}
5 changes: 4 additions & 1 deletion src/test/antunit/TestClassReferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
<forbiddenapis>
<fileset file="Java5ClassReferences.class"/>
java.lang.Integer @ Forbidden class reference!
java.util.List @ Forbidden class reference!
java.util.AbstractCollection @ Forbidden class reference!
java.util.AbstractSet @ Forbidden class reference!
</forbiddenapis>
</au:expectfailure>
<au:assertLogContains level="error" text="java.lang.Integer [Forbidden class reference!]"/>
<au:assertLogContains level="error" text=" 8 error(s)"/>
<au:assertLogContains level="error" text=" 11 error(s)"/>
</target>

</project>

0 comments on commit eaf9785

Please sign in to comment.