Skip to content

Commit

Permalink
If a Method can not be found: a log.warn is enough.
Browse files Browse the repository at this point in the history
It can happen with correct code dealing with interfaces
  • Loading branch information
wojtus committed Dec 17, 2014
1 parent 782e350 commit ccd61ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@
<artifactId>mockito-all</artifactId>
<version>1.10.8</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!-- dependencies for jp.co.worksap.oss.findbugs.jpa package -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.apache.bcel.classfile.AnnotationEntry;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.common.annotations.VisibleForTesting;

Expand All @@ -29,6 +31,8 @@ public class UnexpectedAccessDetector extends BytecodeScanningDetector {
@Nonnull
private final BugReporter bugReporter;

private final transient Log log = LogFactory.getLog(this.getClass());

/**
* @param bugReporter
*/
Expand Down Expand Up @@ -68,7 +72,7 @@ void verifyVisibility(ClassDescriptor invokedClass, MethodDescriptor invokedMeth
JavaClass bcelClass = Repository.getRepository().loadClass(invokedClass.getDottedClassName());
Method bcelMethod = findMethod(bcelClass, invokedMethod);

if (checkVisibility(bcelMethod) && checkAnnotated(bcelMethod)) {
if (bcelMethod != null && checkVisibility(bcelMethod) && checkAnnotated(bcelMethod)) {
BugInstance bug = new BugInstance(this, "GUAVA_UNEXPECTED_ACCESS_TO_VISIBLE_FOR_TESTING", HIGH_PRIORITY);
if (reportCaller) {
bug.addCalledMethod(this).addClassAndMethod(this).addSourceLine(this);
Expand All @@ -85,8 +89,8 @@ Method findMethod(JavaClass bcelClass, MethodDescriptor invokedMethod) {
return bcelMethod;
}
}

throw new IllegalArgumentException("Method not found: " + invokedMethod);
log.warn("Method not found: " + invokedMethod);
return null;
}

/**
Expand Down

0 comments on commit ccd61ee

Please sign in to comment.