diff options
author | cnsun <cnsun@google.com> | 2018-04-17 15:04:01 -0700 |
---|---|---|
committer | Ivan Gavrilovic <gavra@google.com> | 2018-05-04 10:41:11 +0100 |
commit | 59370640f451cdb9b18472324f4234c0dc184755 (patch) | |
tree | bcfe14e5141434ac7fc753ddaaa6ec5f4e31ecb0 /java/com/google | |
parent | ce0be66cf75cd2c13644542b8ecbb18406ac4c32 (diff) | |
download | desugar-59370640f451cdb9b18472324f4234c0dc184755.tar.gz |
Relax the assertion in Desugar for checking the calls to $closeResource(...).
It is possible that $closeResource(...) is not used as the calls to it might
be eliminated by some optimization tools, such as Proguard.
RELNOTES: n/a.
PiperOrigin-RevId: 193262552
GitOrigin-RevId: 1a2ab6d54e2a8749549f41055cd66f3f6dfea4cc
Change-Id: Ifdbd7b47132b541ecfd831d2a7b83d76853ec206
Diffstat (limited to 'java/com/google')
-rw-r--r-- | java/com/google/devtools/build/android/desugar/TryWithResourcesRewriter.java | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/java/com/google/devtools/build/android/desugar/TryWithResourcesRewriter.java b/java/com/google/devtools/build/android/desugar/TryWithResourcesRewriter.java index 818585f..98eef45 100644 --- a/java/com/google/devtools/build/android/desugar/TryWithResourcesRewriter.java +++ b/java/com/google/devtools/build/android/desugar/TryWithResourcesRewriter.java @@ -166,14 +166,12 @@ public class TryWithResourcesRewriter extends ClassVisitor { new CloseResourceMethodSpecializer(cv, resourceInternalName, isInterface)); } } else { + // It is possible that all calls to $closeResources(...) are in dead code regions, and the + // calls are eliminated, which leaving the method $closeResources() unused. (b/78030676). + // In this case, we just discard the method body. checkState( - closeResourceMethod == null, - "The field resourceTypeInternalNames is empty. " - + "But the class has the $closeResource method."); - checkState( - !hasCloseResourceMethod, - "The class %s has close resource method, but resourceTypeInternalNames is empty.", - internalName); + !hasCloseResourceMethod || closeResourceMethod != null, + "There should be $closeResources(...) in the class file."); } super.visitEnd(); } |