Class FindClassCircularDependencies

java.lang.Object
edu.umd.cs.findbugs.visitclass.BetterVisitor
edu.umd.cs.findbugs.visitclass.PreorderVisitor
edu.umd.cs.findbugs.visitclass.AnnotationVisitor
edu.umd.cs.findbugs.visitclass.DismantleBytecode
edu.umd.cs.findbugs.BytecodeScanningDetector
com.mebigfatguy.fbcontrib.detect.FindClassCircularDependencies
All Implemented Interfaces:
edu.umd.cs.findbugs.Detector, edu.umd.cs.findbugs.Priorities, org.apache.bcel.classfile.Visitor

public class FindClassCircularDependencies extends edu.umd.cs.findbugs.BytecodeScanningDetector
looks for classes that have dependencies on each other in a circular way. Class initialization can be compromised in this scenario, and usually points to a bad data model. Consider using interfaces to break this hard circular dependency.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static class 
    finds class dependency loops in a directed graph
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Pattern
     
    private edu.umd.cs.findbugs.BugReporter
     
    private String
     
    private Map<String,Set<String>>
     

    Fields inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode

    codeBytes, lineNumberTable, M_BR, M_CP, M_INT, M_PAD, M_R, M_UINT

    Fields inherited from interface edu.umd.cs.findbugs.Priorities

    EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
  • Constructor Summary

    Constructors
    Constructor
    Description
    FindClassCircularDependencies(edu.umd.cs.findbugs.BugReporter bugReporter)
    constructs a FCCD detector given the reporter to report bugs on
  • Method Summary

    Modifier and Type
    Method
    Description
    private Set<String>
    returns a set of dependent class names for a class, and if it doesn't exist create the set install it, and then return;
    private boolean
    isEnclosingClassName(String outerClass, String innerClass)
     
    private boolean
    isStaticChild(String child, String parent)
     
    private String
     
    private void
     
    private void
     
    private void
     
    private boolean
     
    void
     
    void
    sawOpcode(int seen)
     
    void
    visit(org.apache.bcel.classfile.JavaClass obj)
     
    void
    visitAnnotation(String annotationClass, Map<String,org.apache.bcel.classfile.ElementValue> map, boolean runtimeVisible)
     

    Methods inherited from class edu.umd.cs.findbugs.BytecodeScanningDetector

    getClassContext, shouldVisitCode, visitClassContext

    Methods inherited from class edu.umd.cs.findbugs.visitclass.DismantleBytecode

    afterOpcode, areOppositeBranches, atCatchBlock, beforeOpcode, getBranchFallThrough, getBranchOffset, getBranchTarget, getClassConstantOperand, getClassDescriptorOperand, getCodeByte, getConstantRefOperand, getDefaultSwitchOffset, getDottedClassConstantOperand, getFieldDescriptorOperand, getIntConstant, getLongConstant, getMaxPC, getMethodDescriptorOperand, getNameConstantOperand, getNextCodeByte, getNextOpcode, getNextPC, getOpcode, getPC, getPrevOpcode, getRefConstantOperand, getRefFieldIsStatic, getRegisterOperand, getSigConstantOperand, getStringConstantOperand, getSwitchLabels, getSwitchOffsets, getXClassOperand, getXFieldOperand, getXMethodOperand, isBranch, isMethodCall, isRegisterLoad, isRegisterStore, isRegisterStore, isReturn, isShift, isSwitch, isWideOpcode, printOpCode, sawBranchTo, sawClass, sawDouble, sawField, sawFloat, sawIMethod, sawInt, sawLong, sawMethod, sawRegister, sawString, visit

    Methods inherited from class edu.umd.cs.findbugs.visitclass.AnnotationVisitor

    getAnnotationParameterAsEnum, getAnnotationParameterAsString, getAnnotationParameterAsStringArray, visitAnnotation, visitParameterAnnotation, visitParameterAnnotation, visitSyntheticParameterAnnotation

    Methods inherited from class edu.umd.cs.findbugs.visitclass.PreorderVisitor

    amVisitingMainMethod, asUnsignedByte, doVisitMethod, getClassDescriptor, getClassName, getCode, getConstantPool, getDottedClassName, getDottedFieldSig, getDottedMethodSig, getDottedSuperclassName, getField, getFieldDescriptor, getFieldIsStatic, getFieldName, getFieldSig, getFullyQualifiedFieldName, getFullyQualifiedMethodName, getMethod, getMethodDescriptor, getMethodName, getMethodSig, getMethodVisitOrder, getNumberArguments, getNumberMethodArguments, getPackageName, getSizeOfSurroundingTryBlock, getSizeOfSurroundingTryBlock, getSourceFile, getStringFromIndex, getSuperclassName, getSurroundingCaughtExceptions, getSurroundingCaughtExceptions, getSurroundingCaughtExceptionTypes, getSurroundingTryBlock, getSurroundingTryBlock, getThisClass, getXClass, getXField, getXMethod, hasInterestingClass, hasInterestingMethod, isVisitMethodsInCallOrder, setupVisitorForClass, setVisitMethodsInCallOrder, shouldVisit, toString, visitAfter, visitAfter, visitAnnotationDefault, visitAnnotationEntry, visitBootstrapMethods, visitCode, visitConstantInvokeDynamic, visitConstantMethodHandle, visitConstantMethodType, visitConstantModule, visitConstantPackage, visitConstantPool, visitEnclosingMethod, visitingField, visitingMethod, visitInnerClasses, visitJavaClass, visitLineNumberTable, visitLocalVariableTable, visitMethodParameters, visitParameterAnnotationEntry, visitStackMap, visitStackMapEntry

    Methods inherited from class edu.umd.cs.findbugs.visitclass.BetterVisitor

    clone, report, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitCodeException, visitConstantClass, visitConstantDouble, visitConstantFieldref, visitConstantFloat, visitConstantInteger, visitConstantInterfaceMethodref, visitConstantLong, visitConstantMethodref, visitConstantNameAndType, visitConstantString, visitConstantUtf8, visitConstantValue, visitDeprecated, visitExceptionTable, visitField, visitInnerClass, visitLineNumber, visitLocalVariable, visitLocalVariableTypeTable, visitMethod, visitSignature, visitSourceFile, visitSynthetic, visitUnknown

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.bcel.classfile.Visitor

    visitConstantDynamic, visitMethodParameter, visitModule, visitModuleExports, visitModuleMainClass, visitModuleOpens, visitModulePackages, visitModuleProvides, visitModuleRequires, visitNestHost, visitNestMembers, visitRecord, visitRecordComponent, visitStackMapType
  • Field Details

    • ARRAY_PATTERN

      private static final Pattern ARRAY_PATTERN
    • dependencyGraph

      private Map<String,Set<String>> dependencyGraph
    • bugReporter

      private edu.umd.cs.findbugs.BugReporter bugReporter
    • className

      @DottedClassName private String className
  • Constructor Details

    • FindClassCircularDependencies

      public FindClassCircularDependencies(edu.umd.cs.findbugs.BugReporter bugReporter)
      constructs a FCCD detector given the reporter to report bugs on
      Parameters:
      bugReporter - the sync of bug reports
  • Method Details

    • visit

      public void visit(org.apache.bcel.classfile.JavaClass obj)
      Overrides:
      visit in class edu.umd.cs.findbugs.visitclass.BetterVisitor
    • visitAnnotation

      public void visitAnnotation(@DottedClassName String annotationClass, Map<String,org.apache.bcel.classfile.ElementValue> map, boolean runtimeVisible)
      Overrides:
      visitAnnotation in class edu.umd.cs.findbugs.visitclass.AnnotationVisitor
    • sawOpcode

      public void sawOpcode(int seen)
      Overrides:
      sawOpcode in class edu.umd.cs.findbugs.visitclass.DismantleBytecode
    • processInvoke

      private void processInvoke()
    • processLoadConstant

      private void processLoadConstant()
    • normalizeArrayClass

      @Nullable private String normalizeArrayClass(String clsName)
    • getDependenciesForClass

      private Set<String> getDependenciesForClass(String clsName)
      returns a set of dependent class names for a class, and if it doesn't exist create the set install it, and then return;
      Parameters:
      clsName - the class for which you are trying to get dependencies
      Returns:
      the active set of classes that are dependent on the specified class
    • isEnclosingClassName

      private boolean isEnclosingClassName(String outerClass, String innerClass)
    • report

      public void report()
      Specified by:
      report in interface edu.umd.cs.findbugs.Detector
      Overrides:
      report in class edu.umd.cs.findbugs.BytecodeScanningDetector
    • isStaticChild

      private boolean isStaticChild(String child, String parent)
    • removeDependencyLeaves

      private void removeDependencyLeaves()
    • removeLoopLinks

      private boolean removeLoopLinks(Set<String> loop)