@Override public void visitAfter(JavaClass obj) { int linesNCSS = 1 + methods + fields; if (sawLineNumbers) { linesNCSS += lines.cardinality(); } else { linesNCSS += classCodeSize / 10; } if (stats != null) { stats.addClass(getDottedClassName(), obj.getSourceFileName(), obj.isInterface(), linesNCSS); } totalCodeSize += classCodeSize; totalNCSS += linesNCSS; totalMethods += methods; totalFields += fields; }
@Override public void observeClass(ClassDescriptor classDescriptor) { try { JavaClass javaClass = AnalysisContext.currentAnalysisContext().lookupClass(classDescriptor.toDottedClassName()); String sourceFileName = fileNameFor(javaClass.getPackageName(), javaClass.getSourceFileName()); sourceFileNameCache.put(javaClass.getClassName(), sourceFileName); } catch (ClassNotFoundException e) { // Ignore - should not happen } }
public void setupVisitorForClass(JavaClass obj) { constantPool = obj.getConstantPool(); thisClass = obj; ConstantClass c = (ConstantClass) constantPool.getConstant(obj.getClassNameIndex()); className = getStringFromIndex(c.getNameIndex()); dottedClassName = className.replace('/', '.'); packageName = obj.getPackageName(); sourceFile = obj.getSourceFileName(); dottedSuperclassName = obj.getSuperclassName(); superclassName = dottedSuperclassName.replace('.', '/'); ClassDescriptor cDesc = DescriptorFactory.createClassDescriptor(className); if (!FindBugs.isNoAnalysis()) { try { thisClassInfo = (ClassInfo) Global.getAnalysisCache().getClassAnalysis(XClass.class, cDesc); } catch (CheckedAnalysisException e) { throw new AssertionError("Can't find ClassInfo for " + cDesc); } } super.visitJavaClass(obj); }
/** * Create from Method and bytecode offset in a visited class. * * @param jclass * JavaClass of visited class * @param method * Method in visited class * @param pc * bytecode offset in visited method * @return SourceLineAnnotation describing visited instruction */ public static SourceLineAnnotation fromVisitedInstruction(JavaClass jclass, Method method, int pc) { LineNumberTable lineNumberTable = method.getCode().getLineNumberTable(); String className = jclass.getClassName(); String sourceFile = jclass.getSourceFileName(); if (lineNumberTable == null) { return createUnknown(className, sourceFile, pc, pc); } int startLine = lineNumberTable.getSourceLine(pc); return new SourceLineAnnotation(className, sourceFile, startLine, startLine, pc, pc); }
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())); } } }
/** * Create a SourceLineAnnotation covering an entire method. * * @param javaClass * JavaClass containing the method * @param xmethod * the method * @return a SourceLineAnnotation for the entire method */ public static SourceLineAnnotation forEntireMethod(JavaClass javaClass, XMethod xmethod) { JavaClassAndMethod m = Hierarchy.findMethod(javaClass, xmethod.getName(), xmethod.getSignature()); if (m == null) { return createUnknown(javaClass.getClassName(), javaClass.getSourceFileName()); } else { return forEntireMethod(javaClass, m.getMethod()); } }
/** * Create a SourceLineAnnotation covering an entire method. * * @param javaClass * JavaClass containing the method * @param method * the method * @return a SourceLineAnnotation for the entire method */ public static SourceLineAnnotation forEntireMethod(JavaClass javaClass, @CheckForNull Method method) { String sourceFile = javaClass.getSourceFileName(); if (method == null) { return createUnknown(javaClass.getClassName(), sourceFile); } Code code = method.getCode(); LineNumberTable lineNumberTable = method.getLineNumberTable(); if (code == null || lineNumberTable == null) { return createUnknown(javaClass.getClassName(), sourceFile); } return forEntireMethod(javaClass.getClassName(), sourceFile, lineNumberTable, code.getLength()); }
ConstantPoolGen cpg = classContext.getConstantPoolGen(); MethodGen methodGen = classContext.getMethodGen(method); String sourceFile = classContext.getJavaClass().getSourceFileName();
xf = ((FinalConstant) rhsType).getXField(); String sourceFile = jclass.getSourceFileName(); String bugPattern = "RC_REF_COMPARISON"; int priority = Priorities.HIGH_PRIORITY;
ConstantPoolGen cpg = classContext.getConstantPoolGen(); MethodGen methodGen = classContext.getMethodGen(method); String sourceFile = classContext.getJavaClass().getSourceFileName();
String sourceFile = javaClass.getSourceFileName(); Location location = resource.getLocation(); InstructionHandle handle = location.getHandle();
ConstantPoolGen cpg = classContext.getConstantPoolGen(); String sourceFile = classContext.getJavaClass().getSourceFileName(); if (DEBUG) { String methodName = methodGen.getClassName() + "." + methodGen.getName();
ConstantPoolGen cpg = classContext.getConstantPoolGen(); String sourceFile = classContext.getJavaClass().getSourceFileName(); if (DEBUG) { String methodName = methodGen.getClassName() + "." + methodGen.getName();
bug.addClassAndMethod(methodGen, javaClass.getSourceFileName()); if (sawSeriousTaint) { bug.addString("non-constant SQL string involving HTTP taint");
bug, SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, javaClass.getSourceFileName(), location.getHandle()));
ConstantPoolGen cpg = classContext.getConstantPoolGen(); String sourceFile = classContext.getJavaClass().getSourceFileName(); if (DEBUG) { String methodName = methodGen.getClassName() + "." + methodGen.getName();
String sourceFile = jclass.getSourceFileName(); BugInstance instance = new BugInstance(this, bugPattern, BASE_ES_PRIORITY).addClassAndMethod(methodGen, sourceFile) .addType("Ljava/lang/String;").describe(TypeAnnotation.FOUND_ROLE).addSomeSourceForTopTwoStackValues(classContext, method, location);
IncompatibleTypes result = IncompatibleTypes.getPriorityForAssumingCompatible(lhsType, rhsType, true); if (result != IncompatibleTypes.SEEMS_OK && result != IncompatibleTypes.UNCHECKED) { String sourceFile = jclass.getSourceFileName();
String sourceFile = classContext.getJavaClass().getSourceFileName();
TypeDataflow typeDataflow = classContext.getTypeDataflow(method); String sourceFileName = javaClass.getSourceFileName();