@Override public void visit(Code obj) { stage = synchronizedMethod ? 1 : 0; super.visit(obj); if (synchronizedMethod && stage == 4) { bugReporter.reportBug(new BugInstance(this, "NN_NAKED_NOTIFY", NORMAL_PRIORITY).addClassAndMethod(this) .addSourceLine(this, notifyPC)); } }
@Override protected void accumulateBug() { bugAccumulator.accumulateBug(new BugInstance(this, "NP_OPTIONAL_RETURN_NULL", HIGH_PRIORITY).addClassAndMethod(this), this); }
@Override public void visit(Code obj) { if(!shouldVisitCode){ return; } sawNoSuchElement = false; sawCall = false; super.visit(obj); if (!sawNoSuchElement) { BugInstance bug = new BugInstance(this, "IT_NO_SUCH_ELEMENT", sawCall ? LOW_PRIORITY : NORMAL_PRIORITY); bug.addClassAndMethod(this); bugReporter.reportBug(bug); } }
@Override public void visit(Method obj) { if (isAdapter) { String methodName = obj.getName(); String signature = methodMap.get(methodName); if (!Const.CONSTRUCTOR_NAME.equals(methodName) && signature != null) { if (!signature.equals(obj.getSignature())) { if (!badOverrideMap.keySet().contains(methodName)) { badOverrideMap.put(methodName, new BugInstance(this, "BOA_BADLY_OVERRIDDEN_ADAPTER", NORMAL_PRIORITY) .addClassAndMethod(this).addSourceLine(this)); } } else { badOverrideMap.put(methodName, null); } } } } }
@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)); } }
@Override public void visit(Code obj) { state = 0; sawAnythingElse = false; sawFieldNulling = false; if (inFinalize) { super.visit(obj); bugAccumulator.reportAccumulatedBugs(); if (!sawAnythingElse && sawFieldNulling) { BugInstance bug = new BugInstance(this, "FI_FINALIZER_ONLY_NULLS_FIELDS", HIGH_PRIORITY).addClassAndMethod(this); bugReporter.reportBug(bug); } } }
private void reportBug() { int priority = LOW_PRIORITY; String pattern = "NS_NON_SHORT_CIRCUIT"; if (sawDangerOld) { if (sawNullTestVeryOld) { priority = HIGH_PRIORITY; } if (sawMethodCallOld || sawNumericTestVeryOld && sawArrayDangerOld) { priority = HIGH_PRIORITY; pattern = "NS_DANGEROUS_NON_SHORT_CIRCUIT"; } else { priority = NORMAL_PRIORITY; } } bugAccumulator.accumulateBug(new BugInstance(this, pattern, priority).addClassAndMethod(this), this); }
BugInstance bug = new BugInstance(pattern, NORMAL_PRIORITY ).addClassAndMethod(DumbMethods.this).addSourceLine(DumbMethods.this) .addInt(value).describe(IntAnnotation.INT_VALUE);
@Override public void sawOpcode(int seen) { if (seen == Const.INVOKEVIRTUAL) { String method = getNameConstantOperand(); String signature = getSigConstantOperand(); if ((("getDocumentBase".equals(method) || "getCodeBase".equals(method)) && "()Ljava/net/URL;".equals(signature)) || ("getAppletContext".equals(method) && "()Ljava/applet/AppletContext;".equals(signature)) || ("getParameter".equals(method) && "(Ljava/lang/String;)Ljava/lang/String;".equals(signature))) { bugReporter.reportBug(new BugInstance(this, "BAC_BAD_APPLET_CONSTRUCTOR", NORMAL_PRIORITY) .addClassAndMethod(this).addSourceLine(this)); } } } }
@Override public void visit(Method obj) { if (DEBUG) { System.out.println("FFI: visiting " + getFullyQualifiedMethodName()); } if ("finalize".equals(getMethodName()) && "()V".equals(getMethodSig()) && (obj.getAccessFlags() & (Const.ACC_PUBLIC)) != 0) { bugReporter .reportBug(new BugInstance(this, "FI_PUBLIC_SHOULD_BE_PROTECTED", NORMAL_PRIORITY).addClassAndMethod(this)); } }
@Override protected void accumulateBug() { bugAccumulator.accumulateBug(new BugInstance(this, "NP_BOOLEAN_RETURN_NULL", getMethodName().startsWith("is") ? HIGH_PRIORITY : NORMAL_PRIORITY).addClassAndMethod(this), this); }
new BugInstance(this, "HE_USE_OF_UNHASHABLE_CLASS", priority).addClassAndMethod(this) .addTypeOfNamedClass(type.getClassName()).describe(TypeAnnotation.UNHASHABLE_ROLE).addCalledMethod(this) .addSourceLine(this));
@Override public void sawOpcode(int seen) { if (seen == Const.MONITOREXIT && (getPrevOpcode(2) == Const.MONITORENTER || getPrevOpcode(1) == Const.MONITORENTER)) { bugReporter.reportBug(new BugInstance(this, "ESync_EMPTY_SYNC", NORMAL_PRIORITY).addClassAndMethod(this) .addSourceLine(this)); } } }
@Override public void visit(Method obj) { if (isReservedName(obj.getName())) { BugInstance bug = new BugInstance(this, "NM_FUTURE_KEYWORD_USED_AS_MEMBER_IDENTIFIER", isVisible(obj) ? HIGH_PRIORITY : NORMAL_PRIORITY).addClassAndMethod(this); bugReporter.reportBug(bug); } }
@Override public void sawOpcode(int seen) { if (seen == Const.INVOKEVIRTUAL && "java/util/concurrent/ScheduledThreadPoolExecutor".equals(getClassConstantOperand()) && "setMaximumPoolSize".equals(getNameConstantOperand())) { accumulator.accumulateBug(new BugInstance(DumbMethods.this, "DMI_FUTILE_ATTEMPT_TO_CHANGE_MAXPOOL_SIZE_OF_SCHEDULED_THREAD_POOL_EXECUTOR", HIGH_PRIORITY) .addClassAndMethod(DumbMethods.this), DumbMethods.this); } } }
public void visitLocation(ClassContext classContext, Location location, MethodGen methodGen, LockDataflow dataflow) throws DataflowAnalysisException { ConstantPoolGen cpg = methodGen.getConstantPool(); if (Hierarchy.isMonitorWait(location.getHandle().getInstruction(), cpg)) { int count = dataflow.getFactAtLocation(location).getNumLockedObjects(); if (count > 1) { // A wait with multiple locks held? String sourceFile = javaClass.getSourceFileName(); possibleWaitBugs.add(new BugInstance(this, "TLW_TWO_LOCK_WAIT", HIGH_PRIORITY).addClassAndMethod(methodGen, sourceFile).addSourceLine(classContext, methodGen, sourceFile, location.getHandle())); } } if (Hierarchy.isMonitorNotify(location.getHandle().getInstruction(), cpg)) { int count = dataflow.getFactAtLocation(location).getNumLockedObjects(); if (count > 1) { // A notify with multiple locks held? String sourceFile = javaClass.getSourceFileName(); possibleNotifyLocations.add(SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, location.getHandle())); } } }
@Override public void sawOpcode(int seen) { switch (stage) { case 0: if (seen == Const.MONITORENTER) { stage = 1; } break; case 1: if (seen == Const.INVOKEVIRTUAL && "wait".equals(getNameConstantOperand())) { bugReporter.reportBug(new BugInstance(this, "UW_UNCOND_WAIT", "()V".equals(getSigConstantOperand()) ? NORMAL_PRIORITY : LOW_PRIORITY).addClassAndMethod(this) .addSourceLine(this)); stage = 2; } break; default: break; } } }
@Override public void visit(Method obj) { if (getMethodName().equals("suite") && !obj.isStatic()) { bugReporter.reportBug(new BugInstance(this, "IJU_SUITE_NOT_STATIC", NORMAL_PRIORITY).addClassAndMethod(this)); } if (getMethodName().equals("suite") && obj.getSignature().startsWith("()") && obj.isStatic()) { if ((!obj.getSignature().equals("()Ljunit/framework/Test;") && !obj.getSignature().equals( "()Ljunit/framework/TestSuite;")) || !obj.isPublic()) { bugReporter.reportBug(new BugInstance(this, "IJU_BAD_SUITE_METHOD", NORMAL_PRIORITY).addClassAndMethod(this)); } } }
@Override public void sawOpcode(int seen) { if (state == 0 && seen == Const.ALOAD_0) { state++; } else if (state == 1 && seen == Const.ACONST_NULL) { state++; } else if (state == 2 && seen == Const.PUTFIELD) { bugAccumulator.accumulateBug( new BugInstance(this, "FI_FINALIZER_NULLS_FIELDS", NORMAL_PRIORITY).addClassAndMethod(this) .addReferencedField(this), this); sawFieldNulling = true; state = 0; } else if (seen == Const.RETURN) { state = 0; } else { state = 0; sawAnythingElse = true; } } }
SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, method, condition.getLocation().getHandle().getPosition()); BugInstance bug = new BugInstance(condition.isByType()?"UC_USELESS_CONDITION_TYPE":"UC_USELESS_CONDITION", priority) .addClassAndMethod(methodDescriptor).add(new StringAnnotation(normalize(condition.getTrueCondition()))); if(condition.isByType()) { bug.addType(condition.getSignature()); bug.addSourceLine(methodDescriptor, condition.getDeadCodeLocation()).describe(SourceLineAnnotation.ROLE_UNREACHABLE_CODE);