Fri, 12 Nov 2010 12:34:18 +0000
6970016: Clean up ARM/try-with-resources implementation
Summary: changed Xlint option name from -Xlint:arm to -Xlint:try
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Lint.java Fri Nov 12 12:33:52 2010 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Lint.java Fri Nov 12 12:34:18 2010 +0000 1.3 @@ -212,9 +212,9 @@ 1.4 VARARGS("varargs"), 1.5 1.6 /** 1.7 - * Warn about arm resources 1.8 + * Warn about issues relating to use of try blocks (i.e. try-with-resources) 1.9 */ 1.10 - ARM("arm"); 1.11 + TRY("try"); 1.12 1.13 LintCategory(String option) { 1.14 this(option, false);
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Nov 12 12:33:52 2010 +0000 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Nov 12 12:34:18 2010 +0000 2.3 @@ -252,7 +252,7 @@ 2.4 (base.getTag() == JCTree.IDENT && TreeInfo.name(base) == names._this)) && 2.5 isAssignableAsBlankFinal(v, env)))) { 2.6 if (v.isResourceVariable()) { //TWR resource 2.7 - log.error(pos, "twr.resource.may.not.be.assigned", v); 2.8 + log.error(pos, "try.resource.may.not.be.assigned", v); 2.9 } else { 2.10 log.error(pos, "cant.assign.val.to.final.var", v); 2.11 } 2.12 @@ -1045,11 +1045,11 @@ 2.13 for (JCTree resource : tree.resources) { 2.14 if (resource.getTag() == JCTree.VARDEF) { 2.15 attribStat(resource, tryEnv); 2.16 - chk.checkType(resource, resource.type, syms.autoCloseableType, "twr.not.applicable.to.type"); 2.17 + chk.checkType(resource, resource.type, syms.autoCloseableType, "try.not.applicable.to.type"); 2.18 VarSymbol var = (VarSymbol)TreeInfo.symbolFor(resource); 2.19 var.setData(ElementKind.RESOURCE_VARIABLE); 2.20 } else { 2.21 - attribExpr(resource, tryEnv, syms.autoCloseableType, "twr.not.applicable.to.type"); 2.22 + attribExpr(resource, tryEnv, syms.autoCloseableType, "try.not.applicable.to.type"); 2.23 } 2.24 } 2.25 // Attribute body 2.26 @@ -2258,8 +2258,8 @@ 2.27 ((VarSymbol)sitesym).isResourceVariable() && 2.28 sym.kind == MTH && 2.29 sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) && 2.30 - env.info.lint.isEnabled(Lint.LintCategory.ARM)) { 2.31 - log.warning(tree, "twr.explicit.close.call"); 2.32 + env.info.lint.isEnabled(Lint.LintCategory.TRY)) { 2.33 + log.warning(Lint.LintCategory.TRY, tree, "try.explicit.close.call"); 2.34 } 2.35 2.36 // Disallow selecting a type from an expression
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Fri Nov 12 12:33:52 2010 +0000 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Fri Nov 12 12:34:18 2010 +0000 3.3 @@ -1037,10 +1037,10 @@ 3.4 int nextadrCatch = nextadr; 3.5 3.6 if (!unrefdResources.isEmpty() && 3.7 - lint.isEnabled(Lint.LintCategory.ARM)) { 3.8 + lint.isEnabled(Lint.LintCategory.TRY)) { 3.9 for (Map.Entry<VarSymbol, JCVariableDecl> e : unrefdResources.entrySet()) { 3.10 - log.warning(e.getValue().pos(), 3.11 - "automatic.resource.not.referenced", e.getKey()); 3.12 + log.warning(Lint.LintCategory.TRY, e.getValue().pos(), 3.13 + "try.resource.not.referenced", e.getKey()); 3.14 } 3.15 } 3.16
4.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Nov 12 12:33:52 2010 +0000 4.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Fri Nov 12 12:34:18 2010 +0000 4.3 @@ -1712,7 +1712,7 @@ 4.4 S.nextToken(); 4.5 List<JCTree> resources = List.<JCTree>nil(); 4.6 if (S.token() == LPAREN) { 4.7 - checkAutomaticResourceManagement(); 4.8 + checkTryWithResources(); 4.9 S.nextToken(); 4.10 resources = resources(); 4.11 accept(RPAREN); 4.12 @@ -2970,9 +2970,9 @@ 4.13 allowMulticatch = true; 4.14 } 4.15 } 4.16 - void checkAutomaticResourceManagement() { 4.17 + void checkTryWithResources() { 4.18 if (!allowTWR) { 4.19 - error(S.pos(), "automatic.resource.management.not.supported.in.source", source.name); 4.20 + error(S.pos(), "try.with.resources.not.supported.in.source", source.name); 4.21 allowTWR = true; 4.22 } 4.23 }
5.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Nov 12 12:33:52 2010 +0000 5.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Nov 12 12:34:18 2010 +0000 5.3 @@ -63,8 +63,6 @@ 5.4 anonymous class implements interface; cannot have type arguments 5.5 compiler.err.anon.class.impl.intf.no.qual.for.new=\ 5.6 anonymous class implements interface; cannot have qualifier for new 5.7 -compiler.misc.twr.not.applicable.to.type=\ 5.8 - automatic resource management not applicable to variable type 5.9 compiler.err.array.and.varargs=\ 5.10 cannot declare both {0} and {1} in {2} 5.11 compiler.err.array.dimension.missing=\ 5.12 @@ -183,8 +181,8 @@ 5.13 5.14 compiler.err.final.parameter.may.not.be.assigned=\ 5.15 final parameter {0} may not be assigned 5.16 -compiler.err.twr.resource.may.not.be.assigned=\ 5.17 - automatic resource {0} may not be assigned 5.18 +compiler.err.try.resource.may.not.be.assigned=\ 5.19 + auto-closeable resource {0} may not be assigned 5.20 compiler.err.multicatch.parameter.may.not.be.assigned=\ 5.21 multi-catch parameter {0} may not be assigned 5.22 compiler.err.finally.without.try=\ 5.23 @@ -823,10 +821,10 @@ 5.24 compiler.warn.proc.unmatched.processor.options=\ 5.25 The following options were not recognized by any processor: ''{0}'' 5.26 5.27 -compiler.warn.twr.explicit.close.call=\ 5.28 - [arm] explicit call to close() on an automatic resource 5.29 -compiler.warn.automatic.resource.not.referenced=\ 5.30 - [arm] automatic resource {0} is never referenced in body of corresponding try statement 5.31 +compiler.warn.try.explicit.close.call=\ 5.32 + explicit call to close() on an auto-closeable resource 5.33 +compiler.warn.try.resource.not.referenced=\ 5.34 + auto-closeable resource {0} is never referenced in body of corresponding try statement 5.35 compiler.warn.unchecked.assign=\ 5.36 unchecked assignment: {0} to {1} 5.37 compiler.warn.unchecked.assign.to.var=\ 5.38 @@ -1050,6 +1048,9 @@ 5.39 # compiler.err.no.elem.type=\ 5.40 # \[\*\] cannot have a type 5.41 5.42 +compiler.misc.try.not.applicable.to.type=\ 5.43 + try-with-resources not applicable to variable type 5.44 + 5.45 ##### 5.46 5.47 compiler.err.type.found.req=\ 5.48 @@ -1272,9 +1273,9 @@ 5.49 exotic identifiers #"___" are not supported in -source {0}\n\ 5.50 (use -source 7 or higher to enable exotic identifiers) 5.51 5.52 -compiler.err.automatic.resource.management.not.supported.in.source=\ 5.53 - automatic resource management is not supported in -source {0}\n\ 5.54 -(use -source 7 or higher to enable automatic resource management) 5.55 +compiler.err.try.with.resources.not.supported.in.source=\ 5.56 + try-with-resources is not supported in -source {0}\n\ 5.57 +(use -source 7 or higher to enable try-with-resources) 5.58 5.59 compiler.warn.enum.as.identifier=\ 5.60 as of release 5, ''enum'' is a keyword, and may not be used as an identifier\n\
6.1 --- a/test/tools/javac/TryWithResources/ArmLint.java Fri Nov 12 12:33:52 2010 +0000 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,55 +0,0 @@ 6.4 -/* 6.5 - * @test /nodynamiccopyright/ 6.6 - * @bug 6911256 6964740 6965277 6967065 6.7 - * @author Joseph D. Darcy 6.8 - * @summary Check that -Xlint:arm warnings are generated as expected 6.9 - * @compile/ref=ArmLint.out -Xlint:arm,deprecation -XDrawDiagnostics ArmLint.java 6.10 - */ 6.11 - 6.12 -class ArmLint implements AutoCloseable { 6.13 - private static void test1() { 6.14 - try(ArmLint r1 = new ArmLint(); 6.15 - ArmLint r2 = new ArmLint(); 6.16 - ArmLint r3 = new ArmLint()) { 6.17 - r1.close(); // The resource's close 6.18 - r2.close(42); // *Not* the resource's close 6.19 - // r3 not referenced 6.20 - } 6.21 - 6.22 - } 6.23 - 6.24 - @SuppressWarnings("arm") 6.25 - private static void test2() { 6.26 - try(@SuppressWarnings("deprecation") AutoCloseable r4 = 6.27 - new DeprecatedAutoCloseable()) { 6.28 - // r4 not referenced 6.29 - } catch(Exception e) { 6.30 - ; 6.31 - } 6.32 - } 6.33 - 6.34 - /** 6.35 - * The AutoCloseable method of a resource. 6.36 - */ 6.37 - @Override 6.38 - public void close () { 6.39 - return; 6.40 - } 6.41 - 6.42 - /** 6.43 - * <em>Not</em> the AutoCloseable method of a resource. 6.44 - */ 6.45 - public void close (int arg) { 6.46 - return; 6.47 - } 6.48 -} 6.49 - 6.50 -@Deprecated 6.51 -class DeprecatedAutoCloseable implements AutoCloseable { 6.52 - public DeprecatedAutoCloseable(){super();} 6.53 - 6.54 - @Override 6.55 - public void close () { 6.56 - return; 6.57 - } 6.58 -}
7.1 --- a/test/tools/javac/TryWithResources/ArmLint.out Fri Nov 12 12:33:52 2010 +0000 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,3 +0,0 @@ 7.4 -ArmLint.java:14:15: compiler.warn.twr.explicit.close.call 7.5 -ArmLint.java:13:13: compiler.warn.automatic.resource.not.referenced: r3 7.6 -2 warnings
8.1 --- a/test/tools/javac/TryWithResources/ImplicitFinal.out Fri Nov 12 12:33:52 2010 +0000 8.2 +++ b/test/tools/javac/TryWithResources/ImplicitFinal.out Fri Nov 12 12:34:18 2010 +0000 8.3 @@ -1,2 +1,2 @@ 8.4 -ImplicitFinal.java:14:13: compiler.err.twr.resource.may.not.be.assigned: r 8.5 +ImplicitFinal.java:14:13: compiler.err.try.resource.may.not.be.assigned: r 8.6 1 error
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/tools/javac/TryWithResources/TwrLint.java Fri Nov 12 12:34:18 2010 +0000 9.3 @@ -0,0 +1,55 @@ 9.4 +/* 9.5 + * @test /nodynamiccopyright/ 9.6 + * @bug 6911256 6964740 6965277 6967065 9.7 + * @author Joseph D. Darcy 9.8 + * @summary Check that -Xlint:twr warnings are generated as expected 9.9 + * @compile/ref=TwrLint.out -Xlint:try,deprecation -XDrawDiagnostics TwrLint.java 9.10 + */ 9.11 + 9.12 +class TwrLint implements AutoCloseable { 9.13 + private static void test1() { 9.14 + try(TwrLint r1 = new TwrLint(); 9.15 + TwrLint r2 = new TwrLint(); 9.16 + TwrLint r3 = new TwrLint()) { 9.17 + r1.close(); // The resource's close 9.18 + r2.close(42); // *Not* the resource's close 9.19 + // r3 not referenced 9.20 + } 9.21 + 9.22 + } 9.23 + 9.24 + @SuppressWarnings("try") 9.25 + private static void test2() { 9.26 + try(@SuppressWarnings("deprecation") AutoCloseable r4 = 9.27 + new DeprecatedAutoCloseable()) { 9.28 + // r4 not referenced - but no warning is generated because of @SuppressWarnings 9.29 + } catch(Exception e) { 9.30 + ; 9.31 + } 9.32 + } 9.33 + 9.34 + /** 9.35 + * The AutoCloseable method of a resource. 9.36 + */ 9.37 + @Override 9.38 + public void close () { 9.39 + return; 9.40 + } 9.41 + 9.42 + /** 9.43 + * <em>Not</em> the AutoCloseable method of a resource. 9.44 + */ 9.45 + public void close (int arg) { 9.46 + return; 9.47 + } 9.48 +} 9.49 + 9.50 +@Deprecated 9.51 +class DeprecatedAutoCloseable implements AutoCloseable { 9.52 + public DeprecatedAutoCloseable(){super();} 9.53 + 9.54 + @Override 9.55 + public void close () { 9.56 + return; 9.57 + } 9.58 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/javac/TryWithResources/TwrLint.out Fri Nov 12 12:34:18 2010 +0000 10.3 @@ -0,0 +1,3 @@ 10.4 +TwrLint.java:14:15: compiler.warn.try.explicit.close.call 10.5 +TwrLint.java:13:13: compiler.warn.try.resource.not.referenced: r3 10.6 +2 warnings
11.1 --- a/test/tools/javac/TryWithResources/TwrOnNonResource.out Fri Nov 12 12:33:52 2010 +0000 11.2 +++ b/test/tools/javac/TryWithResources/TwrOnNonResource.out Fri Nov 12 12:34:18 2010 +0000 11.3 @@ -1,7 +1,7 @@ 11.4 -TwrOnNonResource.java:12:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.5 -TwrOnNonResource.java:15:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.6 -TwrOnNonResource.java:18:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.7 -TwrOnNonResource.java:24:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.8 -TwrOnNonResource.java:27:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.9 -TwrOnNonResource.java:30:13: compiler.err.prob.found.req: (compiler.misc.twr.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.10 +TwrOnNonResource.java:12:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.11 +TwrOnNonResource.java:15:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.12 +TwrOnNonResource.java:18:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.13 +TwrOnNonResource.java:24:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.14 +TwrOnNonResource.java:27:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.15 +TwrOnNonResource.java:30:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable 11.16 6 errors
12.1 --- a/test/tools/javac/diags/examples/ResourceClosed.java Fri Nov 12 12:33:52 2010 +0000 12.2 +++ b/test/tools/javac/diags/examples/ResourceClosed.java Fri Nov 12 12:34:18 2010 +0000 12.3 @@ -21,8 +21,8 @@ 12.4 * questions. 12.5 */ 12.6 12.7 -// key: compiler.warn.twr.explicit.close.call 12.8 -// options: -Xlint:arm 12.9 +// key: compiler.warn.try.explicit.close.call 12.10 +// options: -Xlint:try 12.11 12.12 import java.io.*; 12.13
13.1 --- a/test/tools/javac/diags/examples/ResourceMayNotBeAssigned.java Fri Nov 12 12:33:52 2010 +0000 13.2 +++ b/test/tools/javac/diags/examples/ResourceMayNotBeAssigned.java Fri Nov 12 12:34:18 2010 +0000 13.3 @@ -21,7 +21,7 @@ 13.4 * questions. 13.5 */ 13.6 13.7 -// key: compiler.err.twr.resource.may.not.be.assigned 13.8 +// key: compiler.err.try.resource.may.not.be.assigned 13.9 13.10 import java.io.*; 13.11
14.1 --- a/test/tools/javac/diags/examples/ResourceNotApplicableToType.java Fri Nov 12 12:33:52 2010 +0000 14.2 +++ b/test/tools/javac/diags/examples/ResourceNotApplicableToType.java Fri Nov 12 12:34:18 2010 +0000 14.3 @@ -21,7 +21,7 @@ 14.4 * questions. 14.5 */ 14.6 14.7 -// key: compiler.misc.twr.not.applicable.to.type 14.8 +// key: compiler.misc.try.not.applicable.to.type 14.9 // key: compiler.err.prob.found.req 14.10 14.11 class ResourceNotApplicableToType {
15.1 --- a/test/tools/javac/diags/examples/ResourceNotReferenced.java Fri Nov 12 12:33:52 2010 +0000 15.2 +++ b/test/tools/javac/diags/examples/ResourceNotReferenced.java Fri Nov 12 12:34:18 2010 +0000 15.3 @@ -21,8 +21,8 @@ 15.4 * questions. 15.5 */ 15.6 15.7 -// key: compiler.warn.automatic.resource.not.referenced 15.8 -// options: -Xlint:arm 15.9 +// key: compiler.warn.try.resource.not.referenced 15.10 +// options: -Xlint:try 15.11 15.12 import java.io.*; 15.13
16.1 --- a/test/tools/javac/diags/examples/TryResourceNotSupported.java Fri Nov 12 12:33:52 2010 +0000 16.2 +++ b/test/tools/javac/diags/examples/TryResourceNotSupported.java Fri Nov 12 12:34:18 2010 +0000 16.3 @@ -21,7 +21,7 @@ 16.4 * questions. 16.5 */ 16.6 16.7 -// key: compiler.err.automatic.resource.management.not.supported.in.source 16.8 +// key: compiler.err.try.with.resources.not.supported.in.source 16.9 // options: -source 1.6 16.10 16.11 import java.io.*;