edu.umd.cs.findbugs.BugInstance Java Examples

The following examples show how to use edu.umd.cs.findbugs.BugInstance. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilterPatternAction.java    From spotbugs with GNU Lesser General Public License v2.1 7 votes vote down vote up
private String getPatternOrPatternType() {
    if (data instanceof IMarker) {
        BugInstance bug = MarkerUtil.findBugInstanceForMarker((IMarker) data);
        if (bug == null) {
            return null;
        }
        if (useSpecificPattern) {
            // uses specific pattern kind, the naming "Type" is misleading
            return bug.getType();
        }
        // uses pattern type, the naming "Abbrev" is misleading
        return bug.getAbbrev();
    } else if (data instanceof BugPattern) {
        BugPattern pattern = (BugPattern) data;
        if (useSpecificPattern) {
            // uses specific pattern kind, the naming "Type" is misleading
            return pattern.getType();
        }
        // uses pattern type, the naming "Abbrev" is misleading
        return pattern.getAbbrev();
    } else if (data instanceof BugCode) {
        // same as pattern.getAbbrev(): it's pattern type
        return ((BugCode) data).getAbbrev();
    }
    return null;
}
 
Example #2
Source File: InvalidJUnitTest.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void visit(Code obj) {
    if (!directChildOfTestCase && (getMethodName().equals("setUp") || getMethodName().equals("tearDown"))
            && !getMethod().isPrivate() && getMethodSig().equals("()V")) {
        sawSuperCall = false;
        super.visit(obj);
        if (sawSuperCall) {
            return;
        }
        JavaClass we = Lookup.findSuperImplementor(getThisClass(), getMethodName(), "()V", bugReporter);
        if (we != null && !we.getClassName().equals("junit.framework.TestCase")) {
            // OK, got a bug
            int offset = 0;
            if (getMethodName().equals("tearDown")) {
                offset = obj.getCode().length - 1;
            }
            Method superMethod = Lookup.findImplementation(we, getMethodName(), "()V");
            Code superCode = superMethod.getCode();
            if (superCode != null && superCode.getCode().length > 3) {
                bugReporter.reportBug(new BugInstance(this, getMethodName().equals("setUp") ? "IJU_SETUP_NO_SUPER"
                        : "IJU_TEARDOWN_NO_SUPER", NORMAL_PRIORITY).addClassAndMethod(this).addMethod(we, superMethod)
                                .describe(MethodAnnotation.METHOD_OVERRIDDEN).addSourceLine(this, offset));
            }
        }
    }
}
 
Example #3
Source File: CheckAnalysisContextContainedAnnotation.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    switch (seen) {
    default:
        break;
    case Const.IF_ICMPEQ:
    case Const.IF_ICMPNE:
        OpcodeStack.Item left = stack.getStackItem(1);
        OpcodeStack.Item right = stack.getStackItem(0);
        if (bad(left, right) || bad(right, left)) {
            accumulator.accumulateBug(new BugInstance(this, "TESTING", NORMAL_PRIORITY).addClassAndMethod(this)
                    .addValueSource(left, this).addValueSource(right, this)
                    .addString("Just check the sign of the result of compare or compareTo, not specific values such as 1 or -1"), this);
        }
        break;
    }

}
 
Example #4
Source File: JspSpringEvalDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
    public void sawOpcode(int seen) {
        //printOpCode(seen);

//        JspSpringEvalDetector: [0039]  ldc   "${expression}"
//        JspSpringEvalDetector: [0041]  ldc   java/lang/String
//        JspSpringEvalDetector: [0043]  aload_2
//        JspSpringEvalDetector: [0044]  aconst_null
//        JspSpringEvalDetector: [0045]  invokestatic   org/apache/jasper/runtime/PageContextImpl.evaluateExpression (Ljava/lang/String;Ljava/lang/Class;Ljavax/servlet/jsp/PageContext;Lorg/apache/jasper/runtime/ProtectedFunctionMapper;)Ljava/lang/Object;
//        JspSpringEvalDetector: [0048]  checkcast
//        JspSpringEvalDetector: [0051]  invokevirtual   org/springframework/web/servlet/tags/EvalTag.setExpression (Ljava/lang/String;)V

        if (seen == Constants.INVOKEVIRTUAL && getClassConstantOperand().equals("org/springframework/web/servlet/tags/EvalTag")
                && getNameConstantOperand().equals("setExpression") && getSigConstantOperand().equals("(Ljava/lang/String;)V")) {

            if (StackUtils.isVariableString(stack.getStackItem(0))) {
                bugReporter.reportBug(new BugInstance(this, JSP_SPRING_EVAL, Priorities.HIGH_PRIORITY) //
                        .addClass(this).addMethod(this).addSourceLine(this));
            }
        }
    }
 
Example #5
Source File: PropertyPageAdapterFactory.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType == IPropertySheetPage.class) {
        if (adaptableObject instanceof BugExplorerView || adaptableObject instanceof AbstractFindbugsView) {
            return new BugPropertySheetPage();
        }
    }
    if (adapterType == IPropertySource.class) {
        if (adaptableObject instanceof BugPattern || adaptableObject instanceof BugInstance
                || adaptableObject instanceof DetectorFactory || adaptableObject instanceof Plugin
                || adaptableObject instanceof BugGroup
                || adaptableObject instanceof BugAnnotation) {
            return new PropertySource(adaptableObject);
        }
        IMarker marker = Util.getAdapter(IMarker.class, adaptableObject);
        if (!MarkerUtil.isFindBugsMarker(marker)) {
            return null;
        }
        return new MarkerPropertySource(marker);
    }
    return null;
}
 
Example #6
Source File: FindNullDeref.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void reportNullDeref(WarningPropertySet<WarningProperty> propertySet, Location location, String type, int priority,
        @CheckForNull BugAnnotation variable) {

    BugInstance bugInstance = new BugInstance(this, type, priority).addClassAndMethod(classContext.getJavaClass(), method);
    if (variable != null) {
        bugInstance.add(variable);
    } else {
        bugInstance.add(new LocalVariableAnnotation("?", -1, -1));
    }
    bugInstance.addSourceLine(classContext, method, location).describe("SOURCE_LINE_DEREF");

    if (FindBugsAnalysisFeatures.isRelaxedMode()) {
        WarningPropertyUtil.addPropertiesForDataMining(propertySet, classContext, method, location);
    }
    addPropertiesForDereferenceLocations(propertySet, Collections.singleton(location), false);

    propertySet.decorateBugInstance(bugInstance);

    bugReporter.reportBug(bugInstance);
}
 
Example #7
Source File: FieldMatcher.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean match(BugInstance bugInstance) {
    FieldAnnotation fieldAnnotation = null;
    if (role == null || "".equals(role)) {
        fieldAnnotation = bugInstance.getPrimaryField();
    } else {
        for (BugAnnotation a : bugInstance.getAnnotations()) {
            if (a instanceof FieldAnnotation && role.equals(a.getDescription())) {
                fieldAnnotation = (FieldAnnotation) a;
                break;
            }
        }
    }
    return fieldAnnotation != null
            && name.match(fieldAnnotation.getFieldName())
            && (signature == null || signature.match(fieldAnnotation.getFieldSignature()));
}
 
Example #8
Source File: Filter.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Do any prep work needed to perform bug filtering
 *
 * @param origCollection
 */
public void getReady(SortedBugCollection origCollection) {
    if (maybeMutatedAsString != null) {
        HashSet<String> addedIssues = new HashSet<>();
        HashSet<String> removedIssues = new HashSet<>();
        for (BugInstance b : origCollection) {
            if (b.getFirstVersion() == maybeMutated) {
                addedIssues.add(getBugLocation(b));
            } else if (b.getLastVersion() == maybeMutated - 1) {
                removedIssues.add(getBugLocation(b));
            }
        }
        addedIssues.remove(null);
        addedIssues.retainAll(removedIssues);
        mutationPoints = addedIssues;
    }

}
 
Example #9
Source File: MergeSummarizeAndView.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
static public SortedBugCollection union(SortedBugCollection origCollection, SortedBugCollection newCollection) {

        SortedBugCollection result = origCollection.duplicate();

        for (Iterator<BugInstance> i = newCollection.iterator(); i.hasNext();) {
            BugInstance bugInstance = i.next();
            result.add(bugInstance);
        }
        ProjectStats stats = result.getProjectStats();
        ProjectStats stats2 = newCollection.getProjectStats();
        stats.addStats(stats2);

        Project project = result.getProject();
        project.add(newCollection.getProject());

        return result;
    }
 
Example #10
Source File: GeolocationDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void visitClassContext(ClassContext classContext) {
    JavaClass javaClass = classContext.getJavaClass();
    
    //The class extends WebChromeClient
    boolean isWebChromeClient = InterfaceUtils.isSubtype(javaClass, "android.webkit.WebChromeClient");
    
    //Not the target of this detector
    if (!isWebChromeClient) {
        return;
    }
    Method[] methodList = javaClass.getMethods();
    for (Method m : methodList) {
        if (DEBUG) {
            System.out.println(">>> Method: " + m.getName());
        }
        //The presence of onGeolocationPermissionsShowPrompt is not enforce for the moment
        if (!m.getName().equals("onGeolocationPermissionsShowPrompt")) {
            continue;
        }
        //Since the logic implemented need to be analyze by a human, all implementation will be flagged.
        bugReporter.reportBug(new BugInstance(this, ANDROID_GEOLOCATION_TYPE, Priorities.NORMAL_PRIORITY) //
                .addClassAndMethod(javaClass, m));
    }
}
 
Example #11
Source File: XSSRequestWrapperDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void visitClassContext(ClassContext classContext) {
    JavaClass javaClass = classContext.getJavaClass();

    //The class extends HttpServletRequestWrapper
    boolean isRequestWrapper = InterfaceUtils.isSubtype(javaClass, "javax.servlet.http.HttpServletRequestWrapper");

    //Not the target of this detector
    if (!isRequestWrapper) return;

    Method[] methodList = javaClass.getMethods();

    for (Method m : methodList) {
        if (m.getName().equals("stripXSS")) {
            bugReporter.reportBug(new BugInstance(this, XSS_REQUEST_WRAPPER_TYPE, Priorities.NORMAL_PRIORITY) //
                    .addClassAndMethod(javaClass, m));
            return;
        }
    }

}
 
Example #12
Source File: AnonymousLdapDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException {

        ConstantPoolGen cpg = classContext.getConstantPoolGen();
        CFG cfg = classContext.getCFG(m);
        
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
            Location location = i.next();

            Instruction inst = location.getHandle().getInstruction();
            
            if (inst instanceof LDC) {
                LDC ldc = (LDC) inst;
                if (ldc != null) {
                    if("java.naming.security.authentication".equals(ldc.getValue(cpg)) &&
                       "none".equals(ByteCode.getConstantLDC(location.getHandle().getNext(), cpg, String.class))){
                        JavaClass clz = classContext.getJavaClass();
                        bugReporter.reportBug(new BugInstance(this, LDAP_ANONYMOUS, Priorities.LOW_PRIORITY) //
                        .addClass(clz)
                        .addMethod(clz, m)
                        .addSourceLine(classContext, m, location));
                        break;
                    }
                }
            }            
        }
    }
 
Example #13
Source File: FindDeadLocalStores.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * If feature is enabled, suppress warnings where there is at least one live
 * store on the line where the warning would be reported.
 *
 * @param accumulator
 *            BugAccumulator containing warnings for method
 * @param liveStoreSourceLineSet
 *            bitset of lines where at least one live store was seen
 */
private void suppressWarningsIfOneLiveStoreOnLine(BugAccumulator accumulator, BitSet liveStoreSourceLineSet) {
    if (!SUPPRESS_IF_AT_LEAST_ONE_LIVE_STORE_ON_LINE) {
        return;
    }

    // Eliminate any accumulated warnings for instructions
    // that (due to inlining) *can* be live stores.
    entryLoop: for (Iterator<? extends BugInstance> i = accumulator.uniqueBugs().iterator(); i.hasNext();) {

        for (SourceLineAnnotation annotation : accumulator.locations(i.next())) {
            if (liveStoreSourceLineSet.get(annotation.getStartLine())) {
                // This instruction can be a live store; don't report
                // it as a warning.
                i.remove();
                continue entryLoop;
            }
        }
    }
}
 
Example #14
Source File: FindBugsParser.java    From analysis-model with MIT License 6 votes vote down vote up
private void setAffectedLines(final BugInstance warning, final IssueBuilder builder,
        final LineRange primary) {
    Iterator<BugAnnotation> annotationIterator = warning.annotationIterator();
    LineRangeList lineRanges = new LineRangeList();
    while (annotationIterator.hasNext()) {
        BugAnnotation bugAnnotation = annotationIterator.next();
        if (bugAnnotation instanceof SourceLineAnnotation) {
            SourceLineAnnotation annotation = (SourceLineAnnotation) bugAnnotation;
            LineRange lineRange = new LineRange(annotation.getStartLine(), annotation.getEndLine());
            if (!lineRanges.contains(lineRange) && !primary.equals(lineRange)) {
                lineRanges.add(lineRange);
            }
        }
    }
    builder.setLineRanges(lineRanges);
}
 
Example #15
Source File: URLProblems.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void visit(Signature obj) {
    String sig = obj.getSignature();
    for (String s : BAD_SIGNATURES) {
        if (sig.indexOf(s) >= 0) {
            if (visitingField()) {
                bugReporter.reportBug(new BugInstance(this, "DMI_COLLECTION_OF_URLS", HIGH_PRIORITY).addClass(this)
                        .addVisitedField(this));
            } else if (visitingMethod()) {
                bugReporter.reportBug(new BugInstance(this, "DMI_COLLECTION_OF_URLS", HIGH_PRIORITY).addClassAndMethod(this));
            } else {
                bugReporter.reportBug(new BugInstance(this, "DMI_COLLECTION_OF_URLS", HIGH_PRIORITY).addClass(this).addClass(
                        this));
            }
        }
    }
}
 
Example #16
Source File: WaitInLoop.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void visit(Code obj) {
    sawWait = false;
    sawAwait = false;
    waitHasTimeout = false;
    sawNotify = false;
    earliestJump = 9999999;
    super.visit(obj);
    if ((sawWait || sawAwait) && waitAt < earliestJump) {
        String bugType = sawWait ? "WA_NOT_IN_LOOP" : "WA_AWAIT_NOT_IN_LOOP";
        bugReporter.reportBug(new BugInstance(this, bugType, waitHasTimeout ? LOW_PRIORITY : NORMAL_PRIORITY)
                .addClassAndMethod(this).addSourceLine(this, waitAt));
    }
    if (sawNotify) {
        bugReporter.reportBug(new BugInstance(this, "NO_NOTIFY_NOT_NOTIFYALL", LOW_PRIORITY).addClassAndMethod(this)
                .addSourceLine(this, notifyPC));
    }
}
 
Example #17
Source File: ClassMatcher.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean match(BugInstance bugInstance) {
    ClassAnnotation classAnnotation = bugInstance.getPrimaryClass();
    if (role != null && !"".equals(role)) {
        for (BugAnnotation a : bugInstance.getAnnotations()) {
            if (a instanceof ClassAnnotation && role.equals(a.getDescription())) {
                classAnnotation = (ClassAnnotation) a;
                break;
            }
        }
    }
    String bugClassName = classAnnotation.getClassName();
    boolean result = className.match(bugClassName);
    LOG.debug("Matching {} with {}, result = {}", bugClassName, className, result);
    return result;
}
 
Example #18
Source File: StickyBroadcastDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
    public void sawOpcode(int seen) {
        //printOpCode(seen);

        // getClassConstantOperand().equals("java/net/Socket")

        if (seen == Constants.INVOKEVIRTUAL && ( //List of method mark as external file access
                getNameConstantOperand().equals("sendStickyBroadcast") ||
                        getNameConstantOperand().equals("sendStickyOrderedBroadcast") ||
                        getNameConstantOperand().equals("sendStickyBroadcastAsUser") ||
                        getNameConstantOperand().equals("sendStickyOrderedBroadcastAsUser")
        )) {
//            System.out.println(getSigConstantOperand());
            bugReporter.reportBug(new BugInstance(this, ANDROID_STICKY_BROADCAST_TYPE, Priorities.NORMAL_PRIORITY) //
                    .addClass(this).addMethod(this).addSourceLine(this));
        }
    }
 
Example #19
Source File: MarkerUtil.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * As a side-effect this method updates missing line information for some
 * bugs stored in the given bug collection
 *
 * @param project
 * @param theCollection
 * @return never null
 */
public static List<MarkerParameter> createBugParameters(IJavaProject project, BugCollection theCollection,
        IProgressMonitor monitor) {
    List<MarkerParameter> bugParameters = new ArrayList<>();
    if (project == null) {
        FindbugsPlugin.getDefault().logException(new NullPointerException("project is null"), "project is null");
        return bugParameters;
    }
    Iterator<BugInstance> iterator = theCollection.iterator();
    while (iterator.hasNext() && !monitor.isCanceled()) {
        BugInstance bug = iterator.next();
        DetectorFactory detectorFactory = bug.getDetectorFactory();
        if (detectorFactory != null && !detectorFactory.getPlugin().isGloballyEnabled()) {
            continue;
        }
        MarkerParameter mp = createMarkerParameter(project, bug);
        if (mp != null) {
            bugParameters.add(mp);
        }
    }
    return bugParameters;
}
 
Example #20
Source File: PreferZeroLengthArrays.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void visit(Code obj) {
    found.clear();
    // Solution to sourceforge bug 1765925; returning null is the
    // convention used by java.io.File.listFiles()
    if ("listFiles".equals(getMethodName())) {
        return;
    }
    String returnType = getMethodSig().substring(getMethodSig().indexOf(')') + 1);
    if (returnType.startsWith("[")) {
        nullOnTOS = false;
        super.visit(obj);
        if (!found.isEmpty()) {
            BugInstance bug = new BugInstance(this, "PZLA_PREFER_ZERO_LENGTH_ARRAYS", LOW_PRIORITY).addClassAndMethod(this);
            for (SourceLineAnnotation s : found) {
                bug.add(s);
            }
            bugReporter.reportBug(bug);
            found.clear();
        }
    }
}
 
Example #21
Source File: SuppressionDecorator.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void reportBug(@Nonnull BugInstance bugInstance) {

    if (!category.equals(bugInstance.getBugPattern().getCategory())) {
        getDelegate().reportBug(bugInstance);
        return;
    }
    if (check.isEmpty()) {
        return;
    }

    ClassAnnotation c = bugInstance.getPrimaryClass();
    @DottedClassName
    String packageName = c.getPackageName();

    while (true) {
        if (check.contains(packageName)) {
            getDelegate().reportBug(bugInstance);
            return;
        } else if (dontCheck.contains(packageName)) {
            return;
        }
        int i = packageName.lastIndexOf('.');
        if (i < 0) {
            return;
        }
        packageName = packageName.substring(0, i);
    }

}
 
Example #22
Source File: PropPageTitleProvider.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
String getDetails(BugInstance bug) {
    if (bug == null) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    BugPattern pattern = bug.getBugPattern();
    sb.append(" (").append(pattern.getType());
    sb.append(", ").append(pattern.getAbbrev()).append(", ");
    sb.append(pattern.getCategory()).append(", ");
    sb.append(bug.getPriorityString());
    sb.append(")");
    return sb.toString();
}
 
Example #23
Source File: FileUploadFilenameDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {

    if (seen == Constants.INVOKEINTERFACE &&
            (getClassConstantOperand().equals("org/apache/wicket/util/upload/FileItem") ||
                    getClassConstantOperand().equals("org/apache/commons/fileupload/FileItem")) &&
            getNameConstantOperand().equals("getName")) {
        bugReporter.reportBug(new BugInstance(this, FILE_UPLOAD_FILENAME_TYPE, Priorities.NORMAL_PRIORITY) //
                .addClass(this).addMethod(this).addSourceLine(this));
    }

}
 
Example #24
Source File: UselessSubclassMethod.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visitMethod(Method obj) {
    if ((interfaceMethods != null) && ((obj.getAccessFlags() & Const.ACC_ABSTRACT) != 0)) {
        String curDetail = obj.getName() + obj.getSignature();
        for (String infMethodDetail : interfaceMethods) {
            if (curDetail.equals(infMethodDetail)) {
                bugReporter.reportBug(new BugInstance(this, "USM_USELESS_ABSTRACT_METHOD", LOW_PRIORITY).addClassAndMethod(
                        getClassContext().getJavaClass(), obj));
            }
        }
    }
    super.visitMethod(obj);
}
 
Example #25
Source File: MainFrameComponentFactory.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Sets the title of the source tabs for either docking or non-docking
 * versions.
 */
void setSourceTab(String title, @CheckForNull BugInstance bug) {
    JComponent label = mainFrame.getGuiLayout().getSourceViewComponent();
    if (label != null) {
        removeLink(label);
    }
    mainFrame.getGuiLayout().setSourceTitle(title);
}
 
Example #26
Source File: FindUnsatisfiedObligation.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void annotateWarningWithSourceLineInformation(State state, Obligation obligation, BugInstance bugInstance) {
    // The reportPath() method currently does all reporting
    // of source line information.
    if (REPORT_PATH) {
        reportPath(bugInstance, obligation, state);
    }
}
 
Example #27
Source File: SwitchFallthrough.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visit(Code obj) {
    if (DEBUG) {
        System.out.printf("%nVisiting %s%n", getMethodDescriptor());
    }
    reachable = false;
    lastPC = 0;
    biggestJumpTarget = -1;
    found.clear();
    switchHdlr = new SwitchHandler();
    clearAllDeadStores();
    deadStore = null;
    priority = NORMAL_PRIORITY;
    fallthroughDistance = 1000;
    enumType = null;
    super.visit(obj);
    enumType = null;
    if (!found.isEmpty()) {
        if (found.size() >= 4 && priority == NORMAL_PRIORITY) {
            priority = LOW_PRIORITY;
        }
        for (SourceLineAnnotation s : found) {
            bugAccumulator.accumulateBug(new BugInstance(this, "SF_SWITCH_FALLTHROUGH", priority).addClassAndMethod(this), s);
        }
    }

    bugAccumulator.reportAccumulatedBugs();
}
 
Example #28
Source File: JspIncludeDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    //printOpCode(seen);

    //Important sample from \plugin\src\test\webapp\includes\jsp_include_1.jsp
    //org.apache.jasper.runtime.JspRuntimeLibrary
    //JspRuntimeLibrary.include(request, response, (String)PageContextImpl.evaluateExpression("${param.secret_param}", String.class, _jspx_page_context, null), out, false);
    //  JspIncludeDetector: [0119]  invokestatic   org/apache/jasper/runtime/JspRuntimeLibrary.include (Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;Ljavax/servlet/jsp/JspWriter;Z)V

    //Important sample from \plugin\src\test\webapp\includes\jsp_include_3.jsp
    //ImportTag _jspx_th_c_import_0 = (ImportTag)this._jspx_tagPool_c_import_url_nobody.get(ImportTag.class);
    //_jspx_th_c_import_0.setUrl((String)PageContextImpl.evaluateExpression("${param.secret_param}", String.class, _jspx_page_context, null));
    //  JspIncludeDetector: [0051]  invokevirtual   org/apache/taglibs/standard/tag/rt/core/ImportTag.setUrl (Ljava/lang/String;)V


    if (seen == Constants.INVOKESTATIC && ("org/apache/jasper/runtime/JspRuntimeLibrary".equals(getClassConstantOperand()) || "org/apache/sling/scripting/jsp/jasper/runtime/JspRuntimeLibrary".equals(getClassConstantOperand()))
            && getNameConstantOperand().equals("include") && getSigConstantOperand().equals("(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;Ljavax/servlet/jsp/JspWriter;Z)V")) {

        bugReporter.reportBug(new BugInstance(this, JSP_INCLUDE_TYPE, Priorities.HIGH_PRIORITY) //
                .addClass(this).addMethod(this).addSourceLine(this));
    }
    else if (seen == Constants.INVOKEVIRTUAL && getClassConstantOperand().equals("org/apache/taglibs/standard/tag/rt/core/ImportTag")
            && getNameConstantOperand().equals("setUrl") && getSigConstantOperand().equals("(Ljava/lang/String;)V")) {

        bugReporter.reportBug(new BugInstance(this, JSP_INCLUDE_TYPE, Priorities.HIGH_PRIORITY) //
                .addClass(this).addMethod(this).addSourceLine(this));
    }

}
 
Example #29
Source File: UseValueOfResolution.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException {
    Assert.isNotNull(rewrite);
    Assert.isNotNull(workingUnit);

    ClassInstanceCreation primitiveTypeCreation = findPrimitiveTypeCreation(getASTNode(workingUnit,
            bug.getPrimarySourceLineAnnotation()));
    if (primitiveTypeCreation == null) {
        throw new BugResolutionException("Primitive type creation not found.");
    }
    MethodInvocation valueOfInvocation = createValueOfInvocation(rewrite, workingUnit, primitiveTypeCreation);
    rewrite.replace(primitiveTypeCreation, valueOfInvocation, null);
}
 
Example #30
Source File: DontUseEnum.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visit(LocalVariable obj) {
    if (isReservedName(obj.getName())) {
        LocalVariableAnnotation var = new LocalVariableAnnotation(obj.getName(), obj.getIndex(), obj.getStartPC());
        SourceLineAnnotation source = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this, obj.getStartPC());
        BugInstance bug = new BugInstance(this, "NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER", NORMAL_PRIORITY)
                .addClassAndMethod(this).add(var).add(source);
        bugReporter.reportBug(bug);
    }
}