Skip to content

Commit

Permalink
adjust for code review feedback
Browse files Browse the repository at this point in the history
* delete useless inline comment
* add @Item.SpecialKind annotation
* rename getIsOfInterestKind to getKindOfInterest
* rename isGetStackTrace to getStackTraceKind
* rename AbstractDetectorForParameterArray2 to
AbstractExtendedDetectorForParameterArray
  • Loading branch information
vorburger committed May 30, 2018
1 parent cae296d commit 65fae45
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions bug-pattern/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.apt_generated_tests/
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
import com.google.common.base.Objects;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.OpcodeStack.Item;
import jp.skypencil.findbugs.slf4j.parameter.AbstractDetectorForParameterArray2;
import jp.skypencil.findbugs.slf4j.parameter.AbstractExtendedDetectorForParameterArray;

/**
* FindBugs (now SpotBugs) Detector for (ab)use of {@link Throwable#getStackTrace()} in SFL4j logger.
*
* @author Michael Vorburger.ch
*/
public class ManualGetStackTraceDetector extends AbstractDetectorForParameterArray2 {
public class ManualGetStackTraceDetector extends AbstractExtendedDetectorForParameterArray {

@Item.SpecialKind
private final int isGetStackTrace = Item.defineNewSpecialKind("use of throwable getStackTrace");
private final int getStackTraceKind = Item.defineNewSpecialKind("use of throwable getStackTrace");

public ManualGetStackTraceDetector(BugReporter bugReporter) {
super(bugReporter, "SLF4J_GET_STACK_TRACE");
}

@Override
protected int getIsOfInterestKind() {
return isGetStackTrace;
@Item.SpecialKind
protected int getKindOfInterest() {
return getStackTraceKind;
}

@Override
protected boolean isWhatWeWantToDetect(int seen) {
// return false;
return seen == INVOKEVIRTUAL
&& !stack.isTop()
&& getThrowableHandler().checkThrowable(getStack().getStackItem(0))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jp.skypencil.findbugs.slf4j;

import jp.skypencil.findbugs.slf4j.parameter.AbstractDetectorForParameterArray2;
import jp.skypencil.findbugs.slf4j.parameter.AbstractExtendedDetectorForParameterArray;
import jp.skypencil.findbugs.slf4j.parameter.ArrayData;
import com.google.common.base.Objects;

Expand All @@ -9,7 +9,7 @@
import edu.umd.cs.findbugs.OpcodeStack.Item;

@CustomUserValue
public final class ManualMessageDetector extends AbstractDetectorForParameterArray2 {
public final class ManualMessageDetector extends AbstractExtendedDetectorForParameterArray {

@Item.SpecialKind
private final int isMessage = Item.defineNewSpecialKind("message generated by throwable object");
Expand All @@ -19,7 +19,7 @@ public ManualMessageDetector(BugReporter bugReporter) {
}

@Override
protected int getIsOfInterestKind() {
protected int getKindOfInterest() {
return isMessage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import javax.annotation.Nullable;
import jp.skypencil.findbugs.slf4j.parameter.ArrayDataHandler.Strategy;

public abstract class AbstractDetectorForParameterArray2 extends AbstractDetectorForParameterArray {
public abstract class AbstractExtendedDetectorForParameterArray extends AbstractDetectorForParameterArray {

private final String bugPatternName;

public AbstractDetectorForParameterArray2(BugReporter bugReporter, String bugPatternName) {
public AbstractExtendedDetectorForParameterArray(BugReporter bugReporter, String bugPatternName) {
super(bugReporter);
this.bugPatternName = bugPatternName;
}
Expand All @@ -22,7 +22,7 @@ protected final Strategy createArrayCheckStrategy() {
return;
}

if (storedItem.getSpecialKind() == getIsOfInterestKind()) {
if (storedItem.getSpecialKind() == getKindOfInterest()) {
arrayData.mark(true);
}

Expand All @@ -42,7 +42,7 @@ public final void afterOpcode(int seen) {
super.afterOpcode(seen);

if (isInvokingGetMessage && !stack.isTop()) {
stack.getStackItem(0).setSpecialKind(getIsOfInterestKind());
stack.getStackItem(0).setSpecialKind(getKindOfInterest());
}
}

Expand All @@ -60,6 +60,6 @@ protected final void onLog(@Nullable String format, @Nullable ArrayData arrayDat

abstract protected boolean isWhatWeWantToDetect(int seen);

abstract protected int getIsOfInterestKind();
abstract protected int getKindOfInterest();

}
1 change: 1 addition & 0 deletions test-case/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.apt_generated_tests/

0 comments on commit 65fae45

Please sign in to comment.