Class TryWithResourcesJavacFilter.Matcher

java.lang.Object
org.jacoco.core.internal.analysis.filter.AbstractMatcher
org.jacoco.core.internal.analysis.filter.TryWithResourcesJavacFilter.Matcher
Enclosing class:
TryWithResourcesJavacFilter

static class TryWithResourcesJavacFilter.Matcher extends AbstractMatcher
javac from JDK 7 and 8 generates bytecode that is equivalent to the compilation of source code that is described in JLS 14.20.3. try-with-resources:
     Resource r = ...;
     Throwable primaryExc = null;
     try {
         ...
     } finally {
         if (r != null) {
             if (primaryExc != null) {
                 try {
                     r.close();
                 } catch (Throwable suppressedExc) {
                     primaryExc.addSuppressed(suppressedExc);
                 }
             } else {
                 r.close();
             }
         }
     }
 
Case of multiple resources looks like multiple nested try-with-resources statements. javac from JDK 9 EA b160 does the same, but with some optimizations (see JDK-7020499):
  • null check for resource is omitted when it is initialized using new
  • synthetic method $closeResource containing null check of primaryExc and calls to methods addSuppressed and close is used when number of copies of closing logic reaches threshold, null check of resource (if present) is done before call of this method
During matching association between resource and slot of variable is done on exceptional path and is used to find close of resource on normal path. Order of loading variables primaryExc and r is different in different cases, which implies that this order should be determined before association. So TryWithResourcesJavacFilter.Matcher.JavacPattern defines all possible variants that will be tried sequentially.
  • Field Details

    • output

      private final IFilterOutput output
    • expectedOwner

      private String expectedOwner
    • start

      private org.objectweb.asm.tree.AbstractInsnNode start
  • Constructor Details

  • Method Details