From eaf9785cf681bc9cbde8aed31612cb45edce0164 Mon Sep 17 00:00:00 2001 From: uschindler Date: Wed, 16 Apr 2014 14:01:16 +0000 Subject: [PATCH] Fix issue #26: Also look at superclasses and interfaces --- .../de/thetaphi/forbiddenapis/Checker.java | 7 +++++-- src/test/antunit/Java5ClassReferences.class | Bin 796 -> 1020 bytes src/test/antunit/Java5ClassReferences.java | 7 +++++++ src/test/antunit/TestClassReferences.xml | 5 ++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/thetaphi/forbiddenapis/Checker.java b/src/main/java/de/thetaphi/forbiddenapis/Checker.java index cb90abc5..83b200e4 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/Checker.java +++ b/src/main/java/de/thetaphi/forbiddenapis/Checker.java @@ -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; diff --git a/src/test/antunit/Java5ClassReferences.class b/src/test/antunit/Java5ClassReferences.class index 8ecd75b7d782f2104c9c0de9386a257de338f5d8..9a254cfdb46556ac777f98879aaaf9e7a2b24f27 100644 GIT binary patch delta 511 zcmZvYxlY4S5Jiujm`9A+ViF)>-vVJVVGFy2Xh4FBf)2@r6^x=3PJ%?mH=wk91frmz zprheq_yU9&n<$D9&3kk2ow;-0d+hj9#gFgTH=w|QNf&boOmd2OlLhh#7FkmCnk=(o z62nofDhi6VhvLz_QTD5~f=1ujjeF}l^_pLH&V<_2NL=`(id(A(o`(HL-p?OOM>M>q zk!n+qg226NIt=~C|BlA1UbuFt-T1_U7&+la;ZD`qNH^tVIvK8vRk=vRf%R zrA%QGb@r<wr`ItaqC@EP1C2|o(LMR17w5$QSWe11?B!Ywl z3t%y<03n_YqL_KQckVlLzx17-e0;yY1APt*lgyVfEND80MV87ev!baQR#`K+bTvKA zx@O}xInH|O;iyL4QlYA-pQqPpe36cZ@yY0FFdSTJHZ2ibnr+JtyPDXtN8eIoKeNu~ zje~<_O8yUWh)hS0Fj3;bp=c%3L@%gFJ>xtUnK1W?Yy*!D4bk>D$uvz-6U;FCM>(TZ wymbS2jCcA(De%W=?=8D`+eyx9N+Q2~*{aB1NK2^ge{LvkT17u4Zr*b42LzNLu>b%7 diff --git a/src/test/antunit/Java5ClassReferences.java b/src/test/antunit/Java5ClassReferences.java index de93421a..c2db010b 100644 --- a/src/test/antunit/Java5ClassReferences.java +++ b/src/test/antunit/Java5ClassReferences.java @@ -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(); @@ -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; } diff --git a/src/test/antunit/TestClassReferences.xml b/src/test/antunit/TestClassReferences.xml index 7b82ef8e..92d5fd5b 100644 --- a/src/test/antunit/TestClassReferences.xml +++ b/src/test/antunit/TestClassReferences.xml @@ -21,10 +21,13 @@ java.lang.Integer @ Forbidden class reference! + java.util.List @ Forbidden class reference! + java.util.AbstractCollection @ Forbidden class reference! + java.util.AbstractSet @ Forbidden class reference! - + \ No newline at end of file