Class FakedTrackingVariable

All Implemented Interfaces:
InvocationSite, TypeConstants, TypeIds

public class FakedTrackingVariable extends LocalDeclaration
A faked local variable declaration used for keeping track of data flows of a special variable. Certain events will be recorded by changing the null info for this variable. See bug 349326 - [1.7] new warning for missing try-with-resources
  • Field Details

  • Constructor Details

  • Method Details

    • generateCode

      public void generateCode(BlockScope currentScope, CodeStream codeStream)
      Description copied from class: LocalDeclaration
      Code generation for a local declaration: i.e. normal assignment to a local variable + unused variable handling
      Overrides:
      generateCode in class LocalDeclaration
    • resolve

      public void resolve(BlockScope scope)
      Overrides:
      resolve in class LocalDeclaration
    • getCloseTrackingVariable

      public static FakedTrackingVariable getCloseTrackingVariable(Expression expression, FlowInfo flowInfo, FlowContext flowContext, boolean useAnnotations)
      If expression resolves to a value of type AutoCloseable answer the variable that tracks closing of that local. Covers two cases:
      • value is a local variable reference, create tracking variable it if needed.
      • value is an allocation expression, return a preliminary tracking variable if set.
      Returns:
      a new FakedTrackingVariable or null.
    • preConnectTrackerAcrossAssignment

      public static FakedTrackingVariable preConnectTrackerAcrossAssignment(ASTNode location, LocalVariableBinding local, Expression rhs, FlowInfo flowInfo, boolean useAnnotations)
      Before analyzing an assignment of this shape: singleName = new Allocation() connect any tracking variable of the LHS with the allocation on the RHS. Also the assignment is temporarily stored in the tracking variable in case we need to report errors because the assignment leaves the old LHS value unclosed. In this case the assignment should be used as the error location.
      Parameters:
      location - the assignment/local declaration being analyzed
      local - the local variable being assigned to
      rhs - the rhs of the assignment resp. the initialization of the local variable declaration. Precondition: client has already checked that the resolved type of this expression is either a closeable type or NULL.
    • analyseCloseableAllocation

      public static void analyseCloseableAllocation(BlockScope scope, FlowInfo flowInfo, FlowContext flowContext, AllocationExpression allocation)
      Compute/assign a tracking variable for a freshly allocated closeable value, using information from our white lists. See Bug 358903 - Filter practically unimportant resource leak warnings
    • analyseCloseableAcquisition

      public static FlowInfo analyseCloseableAcquisition(BlockScope scope, FlowInfo flowInfo, FlowContext flowContext, MessageSend acquisition)
      Check if a message send acquires a closeable from its receiver, see: Bug 463320 - [compiler][resource] potential "resource leak" problem disappears when local variable inlined
    • handleResourceAssignment

      public static void handleResourceAssignment(BlockScope scope, FlowInfo upstreamInfo, FlowInfo flowInfo, FlowContext flowContext, ASTNode location, Expression rhs, LocalVariableBinding local)
      Given the rhs of an assignment or local declaration has a (Auto)Closeable type (or null), setup for leak analysis now: Create or re-use a tracking variable, and wire and initialize everything.
      Parameters:
      scope - scope containing the assignment
      upstreamInfo - info without analysis of the rhs, use this to determine the status of a resource being disconnected
      flowInfo - info with analysis of the rhs, use this for recording resource status because this will be passed downstream
      location - where to report warnigs/errors against
      rhs - the right hand side of the assignment, this expression is to be analyzed. The caller has already checked that the rhs is either of a closeable type or null.
      local - the local variable into which the rhs is being assigned
    • riskyNullStatusAt

      public int riskyNullStatusAt(FlowInfo info)
    • handleResourceFieldAssignment

      public static void handleResourceFieldAssignment(BlockScope scope, FlowInfo flowInfo, FlowContext flowContext, ASTNode location, Expression rhs)
      When assigning an rhs of an (Auto)Closeable type (or null) to a field, inspect annotations to find out if the assignment assigns ownership to the instance (rather than current method).
      Parameters:
      scope - scope containing the assignment
      flowInfo - info with analysis of the rhs, use this for recording resource status because this will be passed downstream
      location - where to report warnigs/errors against
      rhs - the right hand side of the assignment, this expression is to be analyzed. The caller has already checked that the rhs is either of a closeable type or null.
    • getNullStatusFromMessageSend

      protected static int getNullStatusFromMessageSend(Expression expression)
    • cleanUpAfterAssignment

      public static void cleanUpAfterAssignment(BlockScope currentScope, int lhsBits, Expression expression)
    • cleanUpUnassigned

      public static void cleanUpUnassigned(BlockScope scope, ASTNode location, FlowInfo flowInfo, boolean returnMissingOwning)
      Unassigned closeables are not visible beyond their enclosing statement, immediately report and remove after each statement.
      Parameters:
      returnMissingOwning - at a return statement this signals true when the enclosing method lacks an @Owning annotation.
    • isAnyCloseable

      public static boolean isAnyCloseable(TypeBinding typeBinding)
      Answer wither the given type binding is a subtype of java.lang.AutoCloseable.
    • isCloseableNotWhiteListed

      public static boolean isCloseableNotWhiteListed(TypeBinding typeBinding)
      Answer wither the given type binding is a subtype of java.lang.AutoCloseable.
    • findMostSpecificStatus

      public int findMostSpecificStatus(FlowInfo flowInfo, BlockScope currentScope, BlockScope locationScope)
    • mergeCloseStatus

      public int mergeCloseStatus(BlockScope currentScope, int status, LocalVariableBinding local, BlockScope outerScope)
    • markClose

      public void markClose(FlowInfo flowInfo, FlowContext flowContext)
      Mark that this resource is closed locally.
    • markNullStatus

      public void markNullStatus(FlowInfo flowInfo, FlowContext flowContext, int status)
    • markOwnedByOutside

      public void markOwnedByOutside(FlowInfo flowInfo, FlowContext flowContext)
    • markAllConnected

      public void markAllConnected(Consumer<FakedTrackingVariable> operation)
    • markClosedInNestedMethod

      public void markClosedInNestedMethod()
      Mark that this resource is closed from a nested method (inside a local class).
    • isClosedInNestedMethod

      public boolean isClosedInNestedMethod()
    • markClosedEffectivelyFinal

      public void markClosedEffectivelyFinal()
      Mark that this resource is closed from a try-with-resource with the tracking variable being effectively final).
    • markPassedToOutside

      public static FlowInfo markPassedToOutside(BlockScope scope, Expression expression, FlowInfo flowInfo, FlowContext flowContext, boolean owned)
      Mark that this resource is passed to some outside code (as argument to a method/ctor call or as a return value from the current method), and thus should be considered as potentially closed.
      Parameters:
      owned - should the resource be considered owned by some outside?
    • markForeachElementVar

      public static void markForeachElementVar(LocalDeclaration local)
    • hasDefinitelyNoResource

      public boolean hasDefinitelyNoResource(FlowInfo flowInfo)
      Answer true if we know for sure that no resource is bound to this variable at the point of 'flowInfo'.
    • isClosedInFinallyOfEnclosing

      public boolean isClosedInFinallyOfEnclosing(BlockScope scope)
    • isClosedInFinally

      public boolean isClosedInFinally()
    • isResourceBeingReturned

      public boolean isResourceBeingReturned(FakedTrackingVariable returnedResource, boolean useOwningAnnotation)
      If current is the same as 'returnedResource' or a wrapper thereof, mark as reported and return true, otherwise false. When using @Owning annotation, do not mark as reported, to proceed to precise analysis
    • withdraw

      public void withdraw()
    • recordErrorLocation

      public void recordErrorLocation(ASTNode location, int nullStatus)
    • reportRecordedErrors

      public boolean reportRecordedErrors(Scope scope, int mergedStatus, boolean atDeadEnd)
    • hasRecordedLocations

      public boolean hasRecordedLocations()
    • reportError

      public int reportError(ProblemReporter problemReporter, ASTNode location, int nullStatus)
    • reportExplicitClosing

      public void reportExplicitClosing(ProblemReporter problemReporter)
    • nameForReporting

      public String nameForReporting(ASTNode location, ReferenceContext referenceContext)
    • markAsShared

      public void markAsShared()
    • isShared

      public boolean isShared()
    • isNotOwned

      protected boolean isNotOwned()
    • closeSeen

      public boolean closeSeen()