Class StaticCalendarDetector

All Implemented Interfaces:
Detector, Priorities, org.apache.bcel.classfile.Visitor

public class StaticCalendarDetector extends OpcodeStackDetector
Detector for static fields of type Calendar or DateFormat and their subclasses. Because Calendar is unsafe for multithreaded use, static fields look suspicous. To work correctly, all access would need to be synchronized by the client which cannot be guaranteed.
Author:
Daniel Schneller
  • Constructor Details

    • StaticCalendarDetector

      public StaticCalendarDetector(BugReporter aReporter)
      Creates a new instance of this Detector.
      Parameters:
      aReporter - BugReporter instance to report found problems to.
  • Method Details

    • visit

      public void visit(org.apache.bcel.classfile.JavaClass someObj)
      Remembers the class name and resets temporary fields.
      Overrides:
      visit in class BetterVisitor
    • visit

      public void visit(org.apache.bcel.classfile.ConstantPool pool)
      Overrides:
      visit in class BetterVisitor
    • visit

      public void visit(org.apache.bcel.classfile.Field aField)
      Checks if the visited field is of type Calendar or DateFormat or a subclass of either one. If so and the field is static and non-private it is suspicious and will be reported.
      Overrides:
      visit in class BetterVisitor
    • visitMethod

      public void visitMethod(org.apache.bcel.classfile.Method obj)
      Specified by:
      visitMethod in interface org.apache.bcel.classfile.Visitor
      Overrides:
      visitMethod in class BetterVisitor
    • visit

      public void visit(org.apache.bcel.classfile.Code obj)
      Overrides:
      visit in class DismantleBytecode
    • sawOpcode

      public void sawOpcode(int seen)
      Checks for method invocations ( INVOKEVIRTUAL) call on a static Calendar or DateFormat fields. The OpcodeStack is used to determine if an invocation is done on such a static field.
      Specified by:
      sawOpcode in class OpcodeStackDetector
      Parameters:
      seen - An opcode to be analyzed
      See Also:
    • report

      public void report()
      Description copied from interface: Detector
      This method is called after all classes to be visited. It should be used by any detectors which accumulate information over all visited classes to generate results.
      Specified by:
      report in interface Detector
      Overrides:
      report in class BytecodeScanningDetector