Mercurial > hg > openjdk > aarch64-port > langtools
changeset 2563:944cf6e69067
Merge
author | asaha |
---|---|
date | Thu, 29 May 2014 13:46:36 -0700 |
parents | 434e4ddacaa2 (current diff) e638f33c70c3 (diff) |
children | 1324aa7d3fe7 |
files | .hgtags test/tools/javac/lambda/ErroneousLambdaExpr.java test/tools/javac/lambda/ErroneousLambdaExpr.out test/tools/javac/lambda/TargetType16.out |
diffstat | 159 files changed, 5884 insertions(+), 1356 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Mon May 19 22:00:11 2014 -0700 +++ b/.hgtags Thu May 29 13:46:36 2014 -0700 @@ -245,7 +245,9 @@ afe63d41c699e0e2ee910ef20c41b60603c852a1 jdk8-b121 232b9cf6303aaf451c7000c5f93dfea842e9e9ae jdk8-b122 a345cf28faca8cc49a28241a0a197fd520d25beb jdk8-b123 +d5aab8300d3b51e8043ab5fe5832ef6c6cbb5552 jdk8u20-b00 436176151e85455e74cd1441a2ba96e791c56785 jdk8-b124 +79dc4b992c0a385c1364592801781b747b85c6ca jdk8u20-b01 436176151e85455e74cd1441a2ba96e791c56785 jdk8-b125 ba24b63043626003929927f091e8b84190f39261 jdk8-b126 bb69217ed81202b1a490dc7150dc7cd073689341 jdk8-b127 @@ -277,4 +279,21 @@ 7803caf52e4b12f11e552565f55ef65aeb2be6a5 jdk8u11-b07 a47aa3203c0210def786ab5ee685e97d07e8bf77 jdk8u11-b08 e973a591a2182c0bdbdd9545ab13f83325acf1e6 jdk8u11-b09 +51cade4632608a6c0b8da33f420bd546aecf6faf jdk8u11-b10 +26b33a6ea08810853af37e81c9b435465b289c98 jdk8u20-b02 +a07271bca831cf1bab35a2ffbcebd8e060b2734b jdk8u20-b03 +613c1d9930c9f650e3fc6926215931a85b679c66 jdk8u20-b04 +27c08b9195d17f8e13cb90f6a7c9b6877062464f jdk8u20-b05 +9d81ae1c417a4748f58921c1f8def7f3c401cecd jdk8-b130 +196ab3dcbd28fac1578590684a337f1c7cf505c9 jdk8-b131 +c8a87a58eb3efdd64055566b502c9d4a72ca0996 jdk8-b132 +c6d0108aca9f8f45b9cddeb6e483d464509e0127 jdk8u20-b06 +1a57c569cb811a897691e42049eca33da8f8d761 jdk8u20-b07 +0f821eb7e92b242c878dca68ef63f9626643ee8f jdk8u20-b08 +aa0cb3af23d376e012a142b0531c4f42032fdacf jdk8u20-b09 +a0d9c18a1041c4217db9cda1817f0e348f1be885 jdk8u20-b10 +7ad480b982bf95b8a7290c8769b2698f6aacaf6b jdk8u20-b11 +e101a12a45a777268a2e729803499a7514255e5b jdk8u20-b12 +b5c2375893e2bca1883e5571bd911b6f0b533bf4 jdk8u20-b13 +5d39c29950f4d65e737f99e468427ae6454fa586 jdk8u20-b14 f491f1581f196950c2cb858508dd06601968c417 jdk8u25-b00
--- a/src/share/classes/com/sun/tools/classfile/Attribute.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/classfile/Attribute.java Thu May 29 13:46:36 2014 -0700 @@ -71,10 +71,6 @@ // defer init of standardAttributeClasses until after options set up } - public void setCompat(boolean compat) { - this.compat = compat; - } - public Attribute createAttribute(ClassReader cr, int name_index, byte[] data) throws IOException { if (standardAttributes == null) { @@ -109,9 +105,10 @@ protected void init() { standardAttributes = new HashMap<String,Class<? extends Attribute>>(); standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class); - standardAttributes.put(BootstrapMethods, BootstrapMethods_attribute.class); + standardAttributes.put(BootstrapMethods, BootstrapMethods_attribute.class); standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class); standardAttributes.put(Code, Code_attribute.class); + standardAttributes.put(CompilationID, CompilationID_attribute.class); standardAttributes.put(ConstantValue, ConstantValue_attribute.class); standardAttributes.put(Deprecated, Deprecated_attribute.class); standardAttributes.put(EnclosingMethod, EnclosingMethod_attribute.class); @@ -120,29 +117,23 @@ standardAttributes.put(LineNumberTable, LineNumberTable_attribute.class); standardAttributes.put(LocalVariableTable, LocalVariableTable_attribute.class); standardAttributes.put(LocalVariableTypeTable, LocalVariableTypeTable_attribute.class); - - if (!compat) { // old javap does not recognize recent attributes - standardAttributes.put(MethodParameters, MethodParameters_attribute.class); - standardAttributes.put(CompilationID, CompilationID_attribute.class); - standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class); - standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class); - standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class); - standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class); - standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class); - standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class); - standardAttributes.put(Signature, Signature_attribute.class); - standardAttributes.put(SourceID, SourceID_attribute.class); - } - + standardAttributes.put(MethodParameters, MethodParameters_attribute.class); + standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class); + standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class); + standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class); + standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class); + standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class); + standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class); + standardAttributes.put(Signature, Signature_attribute.class); standardAttributes.put(SourceDebugExtension, SourceDebugExtension_attribute.class); standardAttributes.put(SourceFile, SourceFile_attribute.class); + standardAttributes.put(SourceID, SourceID_attribute.class); standardAttributes.put(StackMap, StackMap_attribute.class); standardAttributes.put(StackMapTable, StackMapTable_attribute.class); standardAttributes.put(Synthetic, Synthetic_attribute.class); } private Map<String,Class<? extends Attribute>> standardAttributes; - private boolean compat; // don't support recent attrs in compatibility mode } public static Attribute read(ClassReader cr) throws IOException {
--- a/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard_ja.properties Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard_ja.properties Thu May 29 13:46:36 2014 -0700 @@ -29,7 +29,7 @@ doclet.Href_Enum_Title={0}\u5185\u306E\u5217\u6319\u578B doclet.Href_Type_Param_Title={0}\u5185\u306E\u578B\u30D1\u30E9\u30E1\u30FC\u30BF doclet.Href_Class_Or_Interface_Title={0}\u5185\u306E\u30AF\u30E9\u30B9\u307E\u305F\u306F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9 -doclet.Summary=\u6982\u8981: +doclet.Summary=\u30B5\u30DE\u30EA\u30FC: doclet.Detail=\u8A73\u7D30: doclet.navNested=\u30CD\u30B9\u30C8 doclet.navAnnotationTypeOptionalMember=\u30AA\u30D7\u30B7\u30E7\u30F3 @@ -117,18 +117,18 @@ doclet.Window_Source_title=\u30BD\u30FC\u30B9\u30FB\u30B3\u30FC\u30C9 doclet.Window_Help_title=API\u30D8\u30EB\u30D7 doclet.Help_line_1=API\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u69CB\u6210 -doclet.Help_line_2=\u3053\u306EAPI(Application Programming Interface)\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306B\u306F\u3001\u6B21\u306B\u8AAC\u660E\u3059\u308B\u30CA\u30D3\u30B2\u30FC\u30B7\u30E7\u30F3\u30FB\u30D0\u30FC\u306B\u3042\u308B\u9805\u76EE\u306B\u5BFE\u5FDC\u3059\u308B\u30DA\u30FC\u30B8\u304C\u542B\u307E\u308C\u307E\u3059\u3002 -doclet.Help_line_3={0}\u30DA\u30FC\u30B8\u306FAPI\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u30D5\u30ED\u30F3\u30C8\u30FB\u30DA\u30FC\u30B8\u3067\u3001\u5404\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u6982\u8981\u3092\u542B\u3080\u5168\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u30EA\u30B9\u30C8\u304C\u8868\u793A\u3055\u308C\u307E\u3059\u3002\u4E00\u9023\u306E\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u6982\u8981\u8AAC\u660E\u3082\u8868\u793A\u3055\u308C\u307E\u3059\u3002 -doclet.Help_line_4=\u5404\u30D1\u30C3\u30B1\u30FC\u30B8\u306B\u306F\u3001\u305D\u306E\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u30AF\u30E9\u30B9\u304A\u3088\u3073\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306E\u30EA\u30B9\u30C8\u3068\u3001\u305D\u308C\u305E\u308C\u306E\u6982\u8981\u3092\u542B\u3080\u30DA\u30FC\u30B8\u304C\u3042\u308A\u307E\u3059\u3002\u3053\u306E\u30DA\u30FC\u30B8\u306F6\u3064\u306E\u30AB\u30C6\u30B4\u30EA\u3067\u69CB\u6210\u3055\u308C\u307E\u3059\u3002 +doclet.Help_line_2=\u3053\u306EAPI (Application Programming Interface)\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306B\u306F\u3001\u6B21\u306B\u8AAC\u660E\u3059\u308B\u30CA\u30D3\u30B2\u30FC\u30B7\u30E7\u30F3\u30FB\u30D0\u30FC\u306B\u3042\u308B\u9805\u76EE\u306B\u5BFE\u5FDC\u3059\u308B\u30DA\u30FC\u30B8\u304C\u542B\u307E\u308C\u307E\u3059\u3002 +doclet.Help_line_3={0}\u30DA\u30FC\u30B8\u306FAPI\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u306E\u30D5\u30ED\u30F3\u30C8\u30FB\u30DA\u30FC\u30B8\u3067\u3001\u5404\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u30B5\u30DE\u30EA\u30FC\u3092\u542B\u3080\u5168\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u30EA\u30B9\u30C8\u304C\u8868\u793A\u3055\u308C\u307E\u3059\u3002\u4E00\u9023\u306E\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u5168\u4F53\u7684\u306A\u8AAC\u660E\u3082\u8868\u793A\u3055\u308C\u307E\u3059\u3002 +doclet.Help_line_4=\u5404\u30D1\u30C3\u30B1\u30FC\u30B8\u306B\u306F\u3001\u305D\u306E\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u30AF\u30E9\u30B9\u304A\u3088\u3073\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306E\u30EA\u30B9\u30C8\u3068\u3001\u305D\u308C\u305E\u308C\u306E\u30B5\u30DE\u30EA\u30FC\u3092\u542B\u3080\u30DA\u30FC\u30B8\u304C\u3042\u308A\u307E\u3059\u3002\u3053\u306E\u30DA\u30FC\u30B8\u306F6\u3064\u306E\u30AB\u30C6\u30B4\u30EA\u3067\u69CB\u6210\u3055\u308C\u307E\u3059\u3002 doclet.Help_line_5=\u30AF\u30E9\u30B9\u307E\u305F\u306F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9 -doclet.Help_line_6=\u5404\u30AF\u30E9\u30B9\u3001\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u3001\u30CD\u30B9\u30C8\u3055\u308C\u305F\u30AF\u30E9\u30B9\u304A\u3088\u3073\u30CD\u30B9\u30C8\u3055\u308C\u305F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306B\u306F\u500B\u5225\u306E\u30DA\u30FC\u30B8\u304C\u3042\u308A\u307E\u3059\u3002\u5404\u30DA\u30FC\u30B8\u306B\u306F\u6B21\u306E\u3088\u3046\u306B\u3001\u30AF\u30E9\u30B9\u307E\u305F\u306F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306E\u8AAC\u660E\u3068\u3001\u6982\u8981\u8868\u304A\u3088\u3073\u30E1\u30F3\u30D0\u30FC\u306E\u8A73\u7D30\u8AAC\u660E\u304C\u542B\u307E\u308C\u307E\u3059\u3002 +doclet.Help_line_6=\u5404\u30AF\u30E9\u30B9\u3001\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u3001\u30CD\u30B9\u30C8\u3055\u308C\u305F\u30AF\u30E9\u30B9\u304A\u3088\u3073\u30CD\u30B9\u30C8\u3055\u308C\u305F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306B\u306F\u500B\u5225\u306E\u30DA\u30FC\u30B8\u304C\u3042\u308A\u307E\u3059\u3002\u5404\u30DA\u30FC\u30B8\u306B\u306F\u6B21\u306E\u3088\u3046\u306B\u3001\u30AF\u30E9\u30B9\u307E\u305F\u306F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306E\u8AAC\u660E\u3068\u3001\u30B5\u30DE\u30EA\u30FC\u8868\u304A\u3088\u3073\u30E1\u30F3\u30D0\u30FC\u306E\u8A73\u7D30\u8AAC\u660E\u304C\u542B\u307E\u308C\u307E\u3059\u3002 doclet.Help_line_7=\u30AF\u30E9\u30B9\u968E\u5C64\u8868\u793A doclet.Help_line_8=\u76F4\u7CFB\u306E\u30B5\u30D6\u30AF\u30E9\u30B9 doclet.Help_line_9=\u65E2\u77E5\u306E\u30B5\u30D6\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306E\u30EA\u30B9\u30C8 doclet.Help_line_10=\u65E2\u77E5\u306E\u5B9F\u88C5\u30AF\u30E9\u30B9\u306E\u30EA\u30B9\u30C8 doclet.Help_line_11=\u30AF\u30E9\u30B9\u307E\u305F\u306F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306E\u5BA3\u8A00 doclet.Help_line_12=\u30AF\u30E9\u30B9\u307E\u305F\u306F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306E\u8AAC\u660E -doclet.Help_line_13=\u5404\u6982\u8981\u30A8\u30F3\u30C8\u30EA\u306B\u306F\u3001\u305D\u306E\u9805\u76EE\u306E\u8A73\u7D30\u306A\u8AAC\u660E\u306E\u4E2D\u304B\u30891\u884C\u76EE\u306E\u6587\u304C\u8868\u793A\u3055\u308C\u307E\u3059\u3002\u8A73\u7D30\u306A\u8AAC\u660E\u306F\u30BD\u30FC\u30B9\u30FB\u30B3\u30FC\u30C9\u306B\u73FE\u308C\u308B\u9806\u306B\u4E26\u3079\u3089\u308C\u307E\u3059\u304C\u3001\u6982\u8981\u30A8\u30F3\u30C8\u30EA\u306F\u30A2\u30EB\u30D5\u30A1\u30D9\u30C3\u30C8\u9806\u306B\u4E26\u3079\u3089\u308C\u307E\u3059\u3002\u3053\u308C\u306B\u3088\u3063\u3066\u3001\u30D7\u30ED\u30B0\u30E9\u30DE\u304C\u8A2D\u5B9A\u3057\u305F\u8AD6\u7406\u7684\u306A\u30B0\u30EB\u30FC\u30D7\u5206\u3051\u304C\u4FDD\u6301\u3055\u308C\u307E\u3059\u3002 +doclet.Help_line_13=\u5404\u30B5\u30DE\u30EA\u30FC\u30FB\u30A8\u30F3\u30C8\u30EA\u306B\u306F\u3001\u305D\u306E\u9805\u76EE\u306E\u8A73\u7D30\u8AAC\u660E\u306E\u4E2D\u304B\u30891\u884C\u76EE\u306E\u6587\u304C\u8868\u793A\u3055\u308C\u307E\u3059\u3002\u30B5\u30DE\u30EA\u30FC\u30FB\u30A8\u30F3\u30C8\u30EA\u306F\u30A2\u30EB\u30D5\u30A1\u30D9\u30C3\u30C8\u9806\u3067\u3059\u304C\u3001\u8A73\u7D30\u8AAC\u660E\u306F\u30BD\u30FC\u30B9\u30FB\u30B3\u30FC\u30C9\u306B\u73FE\u308C\u308B\u9806\u306B\u306A\u3063\u3066\u3044\u307E\u3059\u3002\u3053\u308C\u306B\u3088\u3063\u3066\u3001\u30D7\u30ED\u30B0\u30E9\u30DE\u304C\u8A2D\u5B9A\u3057\u305F\u8AD6\u7406\u7684\u306A\u30B0\u30EB\u30FC\u30D7\u5206\u3051\u304C\u4FDD\u6301\u3055\u308C\u307E\u3059\u3002 doclet.Help_line_14=\u4F7F\u7528 doclet.Help_line_15=\u5404\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u5316\u3055\u308C\u305F\u30D1\u30C3\u30B1\u30FC\u30B8\u3001\u30AF\u30E9\u30B9\u304A\u3088\u3073\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306B\u306F\u305D\u308C\u305E\u308C\u300C\u4F7F\u7528\u300D\u30DA\u30FC\u30B8\u304C\u3042\u308A\u307E\u3059\u3002\u3053\u306E\u30DA\u30FC\u30B8\u306B\u306F\u3001\u3069\u306E\u3088\u3046\u306A\u30D1\u30C3\u30B1\u30FC\u30B8\u3001\u30AF\u30E9\u30B9\u3001\u30E1\u30BD\u30C3\u30C9\u3001\u30B3\u30F3\u30B9\u30C8\u30E9\u30AF\u30BF\u304A\u3088\u3073\u30D5\u30A3\u30FC\u30EB\u30C9\u304C\u3001\u7279\u5B9A\u306E\u30AF\u30E9\u30B9\u307E\u305F\u306F\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u4E00\u90E8\u3092\u4F7F\u7528\u3057\u3066\u3044\u308B\u304B\u304C\u8A18\u8FF0\u3055\u308C\u3066\u3044\u307E\u3059\u3002\u305F\u3068\u3048\u3070\u3001\u30AF\u30E9\u30B9A\u307E\u305F\u306F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9A\u306E\u5834\u5408\u3001\u305D\u306E\u300C\u4F7F\u7528\u300D\u30DA\u30FC\u30B8\u306B\u306F\u3001A\u306E\u30B5\u30D6\u30AF\u30E9\u30B9\u3001A\u3068\u3057\u3066\u5BA3\u8A00\u3055\u308C\u308B\u30D5\u30A3\u30FC\u30EB\u30C9\u3001A\u3092\u8FD4\u3059\u30E1\u30BD\u30C3\u30C9\u3068\u3001\u578BA\u3092\u6301\u3064\u30E1\u30BD\u30C3\u30C9\u304A\u3088\u3073\u30B3\u30F3\u30B9\u30C8\u30E9\u30AF\u30BF\u304C\u542B\u307E\u308C\u307E\u3059\u3002\u3053\u306E\u30DA\u30FC\u30B8\u306B\u30A2\u30AF\u30BB\u30B9\u3059\u308B\u306B\u306F\u3001\u307E\u305A\u305D\u306E\u30D1\u30C3\u30B1\u30FC\u30B8\u3001\u30AF\u30E9\u30B9\u307E\u305F\u306F\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306B\u79FB\u52D5\u3057\u3001\u30CA\u30D3\u30B2\u30FC\u30B7\u30E7\u30F3\u30FB\u30D0\u30FC\u306E\u300C\u4F7F\u7528\u300D\u30EA\u30F3\u30AF\u3092\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u304F\u3060\u3055\u3044\u3002 doclet.Help_line_16=\u968E\u5C64\u30C4\u30EA\u30FC(\u30AF\u30E9\u30B9\u968E\u5C64)
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_ja.properties Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_ja.properties Thu May 29 13:46:36 2014 -0700 @@ -66,22 +66,22 @@ doclet.malformed_html_link_tag=<a> \u30BF\u30B0\u306E\u5F62\u5F0F\u304C\u4E0D\u6B63:\n"{0}" doclet.tag_misuse={0}\u30BF\u30B0\u306F{1}\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u5185\u3067\u306F\u4F7F\u7528\u3067\u304D\u307E\u305B\u3093\u3002\u4F7F\u7528\u3067\u304D\u308B\u306E\u306F\u6B21\u306E\u30BF\u30A4\u30D7\u306E\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u5185\u306E\u307F\u3067\u3059: {2}\u3002 doclet.javafx_tag_misuse=\u30BF\u30B0@propertyGetter\u3001@propertySetter\u304A\u3088\u3073@propertyDescription\u306F\u3001JavaFX\u306E\u30D7\u30ED\u30D1\u30C6\u30A3getter\u3068setter\u306E\u307F\u3067\u4F7F\u7528\u3067\u304D\u307E\u3059\u3002 -doclet.Package_Summary=\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u6982\u8981 +doclet.Package_Summary=\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u30B5\u30DE\u30EA\u30FC doclet.Profile_Summary=\u30D7\u30ED\u30D5\u30A1\u30A4\u30EB\u30FB\u30B5\u30DE\u30EA\u30FC -doclet.Interface_Summary=\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306E\u6982\u8981 -doclet.Annotation_Types_Summary=\u6CE8\u91C8\u578B\u306E\u6982\u8981 -doclet.Enum_Summary=\u5217\u6319\u578B\u306E\u6982\u8981 -doclet.Exception_Summary=\u4F8B\u5916\u306E\u6982\u8981 -doclet.Error_Summary=\u30A8\u30E9\u30FC\u306E\u6982\u8981 -doclet.Class_Summary=\u30AF\u30E9\u30B9\u306E\u6982\u8981 -doclet.Nested_Class_Summary=\u30CD\u30B9\u30C8\u3055\u308C\u305F\u30AF\u30E9\u30B9\u306E\u6982\u8981 -doclet.Annotation_Type_Optional_Member_Summary=\u4EFB\u610F\u8981\u7D20\u306E\u6982\u8981 -doclet.Annotation_Type_Required_Member_Summary=\u5FC5\u9808\u8981\u7D20\u306E\u6982\u8981 -doclet.Field_Summary=\u30D5\u30A3\u30FC\u30EB\u30C9\u306E\u6982\u8981 -doclet.Property_Summary=\u30D7\u30ED\u30D1\u30C6\u30A3\u306E\u6982\u8981 -doclet.Enum_Constant_Summary=\u5217\u6319\u578B\u5B9A\u6570\u306E\u6982\u8981 -doclet.Constructor_Summary=\u30B3\u30F3\u30B9\u30C8\u30E9\u30AF\u30BF\u306E\u6982\u8981 -doclet.Method_Summary=\u30E1\u30BD\u30C3\u30C9\u306E\u6982\u8981 +doclet.Interface_Summary=\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Annotation_Types_Summary=\u6CE8\u91C8\u578B\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Enum_Summary=\u5217\u6319\u578B\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Exception_Summary=\u4F8B\u5916\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Error_Summary=\u30A8\u30E9\u30FC\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Class_Summary=\u30AF\u30E9\u30B9\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Nested_Class_Summary=\u30CD\u30B9\u30C8\u3055\u308C\u305F\u30AF\u30E9\u30B9\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Annotation_Type_Optional_Member_Summary=\u4EFB\u610F\u8981\u7D20\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Annotation_Type_Required_Member_Summary=\u5FC5\u9808\u8981\u7D20\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Field_Summary=\u30D5\u30A3\u30FC\u30EB\u30C9\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Property_Summary=\u30D7\u30ED\u30D1\u30C6\u30A3\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Enum_Constant_Summary=\u5217\u6319\u578B\u5B9A\u6570\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Constructor_Summary=\u30B3\u30F3\u30B9\u30C8\u30E9\u30AF\u30BF\u306E\u30B5\u30DE\u30EA\u30FC +doclet.Method_Summary=\u30E1\u30BD\u30C3\u30C9\u306E\u30B5\u30DE\u30EA\u30FC doclet.Interfaces=\u30A4\u30F3\u30BF\u30D5\u30A7\u30FC\u30B9 doclet.Enums=\u5217\u6319\u578B doclet.AnnotationTypes=\u6CE8\u91C8\u578B
--- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -177,7 +177,7 @@ try { url = adjustEndFileSeparator(url); if (isUrl(pkglisturl)) { - readPackageListFromURL(url, toURL(pkglisturl)); + readPackageListFromURL(url, toURL(adjustEndFileSeparator(pkglisturl))); } else { readPackageListFromFile(url, DocFile.createFileForInput(configuration, pkglisturl)); }
--- a/src/share/classes/com/sun/tools/javac/code/Source.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -191,6 +191,9 @@ public boolean allowObjectToPrimitiveCast() { return compareTo(JDK1_7) >= 0; } + public boolean enforceThisDotInit() { + return compareTo(JDK1_7) >= 0; + } public boolean allowPoly() { return compareTo(JDK1_8) >= 0; } @@ -215,6 +218,9 @@ public boolean allowTypeAnnotations() { return compareTo(JDK1_8) >= 0; } + public boolean allowAnnotationsAfterTypeParams() { + return compareTo(JDK1_8) >= 0; + } public boolean allowRepeatedAnnotations() { return compareTo(JDK1_8) >= 0; } @@ -224,7 +230,7 @@ public boolean allowGraphInference() { return compareTo(JDK1_8) >= 0; } - public boolean allowStructuralMostSpecific() { + public boolean allowFunctionalInterfaceMostSpecific() { return compareTo(JDK1_8) >= 0; } public static SourceVersion toSourceVersion(Source source) {
--- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -392,7 +392,7 @@ /** A class is an inner class if it it has an enclosing instance class. */ public boolean isInner() { - return type.getEnclosingType().hasTag(CLASS); + return kind == TYP && type.getEnclosingType().hasTag(CLASS); } /** An inner class has an outer instance if it is not an interface @@ -467,11 +467,24 @@ private boolean hiddenIn(ClassSymbol clazz, Types types) { Symbol sym = hiddenInInternal(clazz, types); - return sym != null && sym != this; + Assert.check(sym != null, "the result of hiddenInInternal() can't be null"); + /* If we find the current symbol then there is no symbol hiding it + */ + return sym != this; } - private Symbol hiddenInInternal(ClassSymbol c, Types types) { - Scope.Entry e = c.members().lookup(name); + /** This method looks in the supertypes graph that has the current class as the + * initial node, till it finds the current symbol or another symbol that hides it. + * If the current class has more than one supertype (extends one class and + * implements one or more interfaces) then null can be returned, meaning that + * a wrong path in the supertypes graph was selected. Null can only be returned + * as a temporary value, as a result of the recursive call. + */ + private Symbol hiddenInInternal(ClassSymbol currentClass, Types types) { + if (currentClass == owner) { + return this; + } + Scope.Entry e = currentClass.members().lookup(name); while (e.scope != null) { if (e.sym.kind == kind && (kind != MTH || @@ -481,18 +494,19 @@ } e = e.next(); } - List<Symbol> hiddenSyms = List.nil(); - for (Type st : types.interfaces(c.type).prepend(types.supertype(c.type))) { + Symbol hiddenSym = null; + for (Type st : types.interfaces(currentClass.type) + .prepend(types.supertype(currentClass.type))) { if (st != null && (st.hasTag(CLASS))) { Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types); - if (sym != null) { - hiddenSyms = hiddenSyms.prepend(hiddenInInternal((ClassSymbol)st.tsym, types)); + if (sym == this) { + return this; + } else if (sym != null) { + hiddenSym = sym; } } } - return hiddenSyms.contains(this) ? - this : - (hiddenSyms.isEmpty() ? null : hiddenSyms.head); + return hiddenSym; } /** Is this symbol inherited into a given class? @@ -689,10 +703,10 @@ } /** - * A total ordering between type symbols that refines the + * A partial ordering between type symbols that refines the * class inheritance graph. * - * Typevariables always precede other kinds of symbols. + * Type variables always precede other kinds of symbols. */ public final boolean precedes(TypeSymbol that, Types types) { if (this == that)
--- a/src/share/classes/com/sun/tools/javac/code/Type.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1445,12 +1445,19 @@ * Inference variable bound kinds */ public enum InferenceBound { - /** upper bounds */ - UPPER, - /** lower bounds */ - LOWER, - /** equality constraints */ - EQ; + UPPER { + public InferenceBound complement() { return LOWER; } + }, + /** lower bounds */ + LOWER { + public InferenceBound complement() { return UPPER; } + }, + /** equality constraints */ + EQ { + public InferenceBound complement() { return EQ; } + }; + + public abstract InferenceBound complement(); } /** inference variable bounds */ @@ -1481,8 +1488,21 @@ } public String toString() { - if (inst != null) return inst.toString(); - else return qtype + "?"; + return (inst == null) ? qtype + "?" : inst.toString(); + } + + public String debugString() { + String result = "inference var = " + qtype + "\n"; + if (inst != null) { + result += "inst = " + inst + '\n'; + } + for (InferenceBound bound: InferenceBound.values()) { + List<Type> aboundList = bounds.get(bound); + if (aboundList.size() > 0) { + result += bound + " = " + aboundList + '\n'; + } + } + return result; } @Override @@ -1492,8 +1512,7 @@ @Override public Type baseType() { - if (inst != null) return inst.baseType(); - else return this; + return (inst == null) ? this : inst.baseType(); } /** get all bounds of a given kind */ @@ -1624,6 +1643,9 @@ //only change bounds if request comes from substBounds super.addBound(ib, bound, types, update); } + else if (bound.hasTag(UNDETVAR) && !((UndetVar) bound).isCaptured()) { + ((UndetVar) bound).addBound(ib.complement(), this, types, false); + } } @Override
--- a/src/share/classes/com/sun/tools/javac/code/Types.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,6 +43,7 @@ import com.sun.tools.javac.comp.Enter; import com.sun.tools.javac.comp.Env; import com.sun.tools.javac.jvm.ClassReader; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.*; import static com.sun.tools.javac.code.BoundKind.*; import static com.sun.tools.javac.code.Flags.*; @@ -84,7 +85,6 @@ final boolean allowBoxing; final boolean allowCovariantReturns; final boolean allowObjectToPrimitiveCast; - final boolean allowDefaultMethods; final ClassReader reader; final Check chk; final Enter enter; @@ -111,7 +111,6 @@ allowBoxing = source.allowBoxing(); allowCovariantReturns = source.allowCovariantReturns(); allowObjectToPrimitiveCast = source.allowObjectToPrimitiveCast(); - allowDefaultMethods = source.allowDefaultMethods(); reader = ClassReader.instance(context); chk = Check.instance(context); enter = Enter.instance(context); @@ -153,31 +152,31 @@ }; // </editor-fold> - // <editor-fold defaultstate="collapsed" desc="lowerBound"> + // <editor-fold defaultstate="collapsed" desc="wildLowerBound"> /** - * The "lvalue conversion".<br> - * The lower bound of most types is the type - * itself. Wildcards, on the other hand have upper - * and lower bounds. - * @param t a type - * @return the lower bound of the given type + * Get a wildcard's lower bound, returning non-wildcards unchanged. + * @param t a type argument, either a wildcard or a type */ - public Type lowerBound(Type t) { - return lowerBound.visit(t); + public Type wildLowerBound(Type t) { + if (t.hasTag(WILDCARD)) { + WildcardType w = (WildcardType) t; + return w.isExtendsBound() ? syms.botType : wildLowerBound(w.type); + } + else return t; } - // where - private final MapVisitor<Void> lowerBound = new MapVisitor<Void>() { - - @Override - public Type visitWildcardType(WildcardType t, Void ignored) { - return t.isExtendsBound() ? syms.botType : visit(t.type); - } - - @Override - public Type visitCapturedType(CapturedType t, Void ignored) { - return visit(t.getLowerBound()); - } - }; + // </editor-fold> + + // <editor-fold defaultstate="collapsed" desc="cvarLowerBound"> + /** + * Get a capture variable's lower bound, returning other types unchanged. + * @param t a type + */ + public Type cvarLowerBound(Type t) { + if (t.hasTag(TYPEVAR) && ((TypeVar) t).isCaptured()) { + return cvarLowerBound(t.getLowerBound()); + } + else return t; + } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="isUnbounded"> @@ -307,8 +306,8 @@ } /** - * Is t a subtype of or convertiable via boxing/unboxing - * convertions to s? + * Is t a subtype of or convertible via boxing/unboxing + * conversions to s? */ public boolean isConvertible(Type t, Type s) { return isConvertible(t, s, noWarnings); @@ -829,9 +828,15 @@ return true; } - Type lower = lowerBound(s); - if (s != lower) - return isSubtype(capture ? capture(t) : t, lower, false); + // Generally, if 's' is a type variable, recur on lower bound; but + // for inference variables and intersections, we need to keep 's' + // (see JLS 4.10.2 for intersections and 18.2.3 for inference vars) + if (!t.hasTag(UNDETVAR) && !t.isCompound()) { + // TODO: JDK-8039198, bounds checking sometimes passes in a wildcard as s + Type lower = cvarLowerBound(wildLowerBound(s)); + if (s != lower) + return isSubtype(capture ? capture(t) : t, lower, false); + } return isSubtype.visit(capture ? capture(t) : t, s); } @@ -915,14 +920,11 @@ @Override public Boolean visitClassType(ClassType t, Type s) { Type sup = asSuper(t, s.tsym); - return sup != null - && sup.tsym == s.tsym - // You're not allowed to write - // Vector<Object> vec = new Vector<String>(); - // But with wildcards you can write - // Vector<? extends Object> vec = new Vector<String>(); - // which means that subtype checking must be done - // here instead of same-type checking (via containsType). + if (sup == null) return false; + // If t is an intersection, sup might not be a class type + if (!sup.hasTag(CLASS)) return isSubtypeNoCapture(sup, s); + return sup.tsym == s.tsym + // Check type variable containment && (!s.isParameterized() || containsTypeRecursive(s, sup)) && isSubtypeNoCapture(sup.getEnclosingType(), s.getEnclosingType()); @@ -1138,7 +1140,7 @@ return visit(s, t); if (s.isSuperBound() && !s.isExtendsBound()) - return visit(t, upperBound(s)) && visit(t, lowerBound(s)); + return visit(t, upperBound(s)) && visit(t, wildLowerBound(s)); if (t.isCompound() && s.isCompound()) { if (!visit(supertype(t), supertype(s))) @@ -1293,7 +1295,7 @@ break; } case SUPER: { - Type bound = lowerBound(s); + Type bound = wildLowerBound(s); undetvar.addBound(InferenceBound.LOWER, bound, this); break; } @@ -1386,9 +1388,9 @@ // t.isSuperBound() // || isSubtypeNoCapture(upperBound(s), U(t))); // System.err.format(" %s L(%s) <: L(%s) %s = %s%n", -// L(t), t, s, lowerBound(s), +// L(t), t, s, wildLowerBound(s), // t.isExtendsBound() -// || isSubtypeNoCapture(L(t), lowerBound(s))); +// || isSubtypeNoCapture(L(t), wildLowerBound(s))); // System.err.println(); // } @@ -1400,7 +1402,7 @@ // debugContainsType(t, s); return isSameWildcard(t, s) || isCaptureOf(s, t) - || ((t.isExtendsBound() || isSubtypeNoCapture(L(t), lowerBound(s))) && + || ((t.isExtendsBound() || isSubtypeNoCapture(L(t), wildLowerBound(s))) && (t.isSuperBound() || isSubtypeNoCapture(upperBound(s), U(t)))); } } @@ -1762,7 +1764,7 @@ if (s.isExtendsBound()) return !isCastableRecursive(t.type, upperBound(s)); else if (s.isSuperBound()) - return notSoftSubtypeRecursive(lowerBound(s), t.type); + return notSoftSubtypeRecursive(wildLowerBound(s), t.type); } else if (t.isSuperBound()) { if (s.isExtendsBound()) return notSoftSubtypeRecursive(t.type, upperBound(s)); @@ -1772,19 +1774,13 @@ }; // </editor-fold> - // <editor-fold defaultstate="collapsed" desc="lowerBoundArgtypes"> - /** - * Returns the lower bounds of the formals of a method. - */ - public List<Type> lowerBoundArgtypes(Type t) { - return lowerBounds(t.getParameterTypes()); + // <editor-fold defaultstate="collapsed" desc="cvarLowerBounds"> + public List<Type> cvarLowerBounds(List<Type> ts) { + return map(ts, cvarLowerBoundMapping); } - public List<Type> lowerBounds(List<Type> ts) { - return map(ts, lowerBoundMapping); - } - private final Mapping lowerBoundMapping = new Mapping("lowerBound") { + private final Mapping cvarLowerBoundMapping = new Mapping("cvarLowerBound") { public Type apply(Type t) { - return lowerBound(t); + return cvarLowerBound(t); } }; // </editor-fold> @@ -1936,6 +1932,17 @@ * @param sym a symbol */ public Type asSuper(Type t, Symbol sym) { + /* Some examples: + * + * (Enum<E>, Comparable) => Comparable<E> + * (c.s.s.d.AttributeTree.ValueKind, Enum) => Enum<c.s.s.d.AttributeTree.ValueKind> + * (c.s.s.t.ExpressionTree, c.s.s.t.Tree) => c.s.s.t.Tree + * (j.u.List<capture#160 of ? extends c.s.s.d.DocTree>, Iterable) => + * Iterable<capture#160 of ? extends c.s.s.d.DocTree> + */ + if (sym.type == syms.objectType) { //optimization + return syms.objectType; + } return asSuper.visit(t, sym); } // where @@ -1951,16 +1958,18 @@ return t; Type st = supertype(t); - if (st.hasTag(CLASS) || st.hasTag(TYPEVAR) || st.hasTag(ERROR)) { + if (st.hasTag(CLASS) || st.hasTag(TYPEVAR)) { Type x = asSuper(st, sym); if (x != null) return x; } if ((sym.flags() & INTERFACE) != 0) { for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) { - Type x = asSuper(l.head, sym); - if (x != null) - return x; + if (!l.head.hasTag(ERROR)) { + Type x = asSuper(l.head, sym); + if (x != null) + return x; + } } } return null; @@ -2242,7 +2251,8 @@ // <editor-fold defaultstate="collapsed" desc="makeCompoundType"> /** - * Make a compound type from non-empty list of types + * Make a compound type from non-empty list of types. The list should be + * ordered according to {@link Symbol#precedes(TypeSymbol,Types)}. * * @param bounds the types from which the compound type is formed * @param supertype is objectType if all bounds are interfaces, @@ -3332,12 +3342,15 @@ * Insert a type in a closure */ public List<Type> insert(List<Type> cl, Type t) { - if (cl.isEmpty() || t.tsym.precedes(cl.head.tsym, this)) { + if (cl.isEmpty()) { return cl.prepend(t); - } else if (cl.head.tsym.precedes(t.tsym, this)) { + } else if (t.tsym == cl.head.tsym) { + return cl; + } else if (t.tsym.precedes(cl.head.tsym, this)) { + return cl.prepend(t); + } else { + // t comes after head, or the two are unrelated return insert(cl.tail, t).prepend(cl.head); - } else { - return cl; } } @@ -3349,12 +3362,15 @@ return cl2; } else if (cl2.isEmpty()) { return cl1; + } else if (cl1.head.tsym == cl2.head.tsym) { + return union(cl1.tail, cl2.tail).prepend(cl1.head); } else if (cl1.head.tsym.precedes(cl2.head.tsym, this)) { return union(cl1.tail, cl2).prepend(cl1.head); } else if (cl2.head.tsym.precedes(cl1.head.tsym, this)) { return union(cl1, cl2.tail).prepend(cl2.head); } else { - return union(cl1.tail, cl2.tail).prepend(cl1.head); + // unrelated types + return union(cl1.tail, cl2).prepend(cl1.head); } } @@ -3464,18 +3480,31 @@ private List<Type> closureMin(List<Type> cl) { ListBuffer<Type> classes = new ListBuffer<>(); ListBuffer<Type> interfaces = new ListBuffer<>(); + Set<Type> toSkip = new HashSet<>(); while (!cl.isEmpty()) { Type current = cl.head; - if (current.isInterface()) - interfaces.append(current); - else - classes.append(current); - ListBuffer<Type> candidates = new ListBuffer<>(); - for (Type t : cl.tail) { - if (!isSubtypeNoCapture(current, t)) - candidates.append(t); + boolean keep = !toSkip.contains(current); + if (keep && current.hasTag(TYPEVAR)) { + // skip lower-bounded variables with a subtype in cl.tail + for (Type t : cl.tail) { + if (isSubtypeNoCapture(t, current)) { + keep = false; + break; + } + } } - cl = candidates.toList(); + if (keep) { + if (current.isInterface()) + interfaces.append(current); + else + classes.append(current); + for (Type t : cl.tail) { + // skip supertypes of 'current' in cl.tail + if (isSubtypeNoCapture(current, t)) + toSkip.add(t); + } + } + cl = cl.tail; } return classes.appendList(interfaces).toList(); } @@ -3635,7 +3664,19 @@ return s; List<Type> closure = union(closure(t), closure(s)); - List<Type> bounds = closureMin(closure); + return glbFlattened(closure, t); + } + //where + /** + * Perform glb for a list of non-primitive, non-error, non-compound types; + * redundant elements are removed. Bounds should be ordered according to + * {@link Symbol#precedes(TypeSymbol,Types)}. + * + * @param flatBounds List of type to glb + * @param errT Original type to use if the result is an error type + */ + private Type glbFlattened(List<Type> flatBounds, Type errT) { + List<Type> bounds = closureMin(flatBounds); if (bounds.isEmpty()) { // length == 0 return syms.objectType; @@ -3643,11 +3684,21 @@ return bounds.head; } else { // length > 1 int classCount = 0; - for (Type bound : bounds) - if (!bound.isInterface()) + List<Type> lowers = List.nil(); + for (Type bound : bounds) { + if (!bound.isInterface()) { classCount++; - if (classCount > 1) - return createErrorType(t); + Type lower = cvarLowerBound(bound); + if (bound != lower && !lower.hasTag(BOT)) + lowers = insert(lowers, lower); + } + } + if (classCount > 1) { + if (lowers.isEmpty()) + return createErrorType(errT); + else + return glbFlattened(union(bounds, lowers), errT); + } } return makeCompoundType(bounds); } @@ -3871,9 +3922,11 @@ } return buf.reverse(); } + public Type capture(Type t) { - if (!t.hasTag(CLASS)) + if (!t.hasTag(CLASS)) { return t; + } if (t.getEnclosingType() != Type.noType) { Type capturedEncl = capture(t.getEnclosingType()); if (capturedEncl != t.getEnclosingType()) { @@ -4125,7 +4178,7 @@ if (source.isExtendsBound()) adaptRecursive(upperBound(source), upperBound(target)); else if (source.isSuperBound()) - adaptRecursive(lowerBound(source), lowerBound(target)); + adaptRecursive(wildLowerBound(source), wildLowerBound(target)); return null; } @@ -4137,7 +4190,7 @@ Type val = mapping.get(source.tsym); if (val != null) { if (val.isSuperBound() && target.isSuperBound()) { - val = isSubtype(lowerBound(val), lowerBound(target)) + val = isSubtype(wildLowerBound(val), wildLowerBound(target)) ? target : val; } else if (val.isExtendsBound() && target.isExtendsBound()) { val = isSubtype(upperBound(val), upperBound(target)) @@ -4251,7 +4304,7 @@ } public Type visitType(Type t, Void s) { - return high ? upperBound(t) : lowerBound(t); + return high ? upperBound(t) : t; } @Override
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -249,7 +249,7 @@ if (!owntype.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) { if (allowPoly && inferenceContext.free(found)) { if ((ownkind & ~resultInfo.pkind) == 0) { - owntype = resultInfo.check(tree, inferenceContext.asFree(owntype)); + owntype = resultInfo.check(tree, inferenceContext.asUndetVar(owntype)); } else { log.error(tree.pos(), "unexpected.type", kindNames(resultInfo.pkind), @@ -518,6 +518,10 @@ return new ResultInfo(pkind, pt, newContext); } + protected ResultInfo dup(Type newPt, CheckContext newContext) { + return new ResultInfo(pkind, newPt, newContext); + } + @Override public String toString() { if (pt != null) { @@ -812,6 +816,10 @@ boolean classExpected, boolean interfaceExpected, boolean checkExtensible) { + if (t.tsym.isAnonymous()) { + log.error(tree.pos(), "cant.inherit.from.anon"); + return types.createErrorType(t); + } if (t.isErroneous()) return t; if (t.hasTag(TYPEVAR) && !classExpected && !interfaceExpected) { @@ -2139,6 +2147,11 @@ cdef.extending = clazz; } + if (resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK && + isSerializable(clazztype)) { + localEnv.info.isSerializable = true; + } + attribStat(cdef, localEnv); checkLambdaCandidate(tree, cdef.sym, clazztype); @@ -2294,6 +2307,9 @@ resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK; try { Type currentTarget = pt(); + if (needsRecovery && isSerializable(currentTarget)) { + localEnv.info.isSerializable = true; + } List<Type> explicitParamTypes = null; if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) { //attribute lambda parameters @@ -2398,7 +2414,7 @@ //add thrown types as bounds to the thrown types free variables if needed: if (resultInfo.checkContext.inferenceContext().free(lambdaType.getThrownTypes())) { List<Type> inferredThrownTypes = flow.analyzeLambdaThrownTypes(env, that, make); - List<Type> thrownTypes = resultInfo.checkContext.inferenceContext().asFree(lambdaType.getThrownTypes()); + List<Type> thrownTypes = resultInfo.checkContext.inferenceContext().asUndetVars(lambdaType.getThrownTypes()); chk.unhandled(inferredThrownTypes, thrownTypes); } @@ -2539,7 +2555,7 @@ @Override public boolean compatible(Type found, Type req, Warner warn) { //return type must be compatible in both current context and assignment context - return chk.basicHandler.compatible(found, inferenceContext().asFree(req), warn); + return chk.basicHandler.compatible(found, inferenceContext().asUndetVar(req), warn); } @Override @@ -2572,7 +2588,7 @@ * types must be compatible with the return type of the expected descriptor. */ private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext) { - Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType()); + Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType()); //return values have already been checked - but if lambda has no return //values, we must ensure that void/value compatibility is correct; @@ -2584,7 +2600,7 @@ diags.fragment("missing.ret.val", returnType))); } - List<Type> argTypes = checkContext.inferenceContext().asFree(descriptor.getParameterTypes()); + List<Type> argTypes = checkContext.inferenceContext().asUndetVars(descriptor.getParameterTypes()); if (!types.isSameTypes(argTypes, TreeInfo.types(tree.params))) { checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda")); } @@ -2614,7 +2630,7 @@ * - an instance field, we use the first constructor. * - a static field, we create a fake clinit method. */ - private Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) { + public Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) { Env<AttrContext> lambdaEnv; Symbol owner = env.info.scope.owner; if (owner.kind == VAR && owner.owner.kind == TYP) { @@ -2698,17 +2714,20 @@ typeargtypes = attribTypes(that.typeargs, localEnv); } - Type target; Type desc; - if (pt() != Type.recoveryType) { - target = targetChecker.visit(pt(), that); - desc = types.findDescriptorType(target); + Type currentTarget = pt(); + boolean isTargetSerializable = + resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK && + isSerializable(currentTarget); + if (currentTarget != Type.recoveryType) { + currentTarget = targetChecker.visit(currentTarget, that); + desc = types.findDescriptorType(currentTarget); } else { - target = Type.recoveryType; + currentTarget = Type.recoveryType; desc = fallbackDescriptorType(that); } - setFunctionalInfo(localEnv, that, pt(), desc, target, resultInfo.checkContext); + setFunctionalInfo(localEnv, that, pt(), desc, currentTarget, resultInfo.checkContext); List<Type> argtypes = desc.getParameterTypes(); Resolve.MethodCheck referenceCheck = rs.resolveMethodCheck; @@ -2750,7 +2769,7 @@ targetError = false; } - JCDiagnostic detailsDiag = ((Resolve.ResolveError)refSym).getDiagnostic(JCDiagnostic.DiagnosticType.FRAGMENT, + JCDiagnostic detailsDiag = ((Resolve.ResolveError)refSym.baseSymbol()).getDiagnostic(JCDiagnostic.DiagnosticType.FRAGMENT, that, exprType.tsym, exprType, that.name, argtypes, typeargtypes); JCDiagnostic.DiagnosticType diagKind = targetError ? @@ -2759,10 +2778,10 @@ JCDiagnostic diag = diags.create(diagKind, log.currentSource(), that, "invalid.mref", Kinds.kindName(that.getMode()), detailsDiag); - if (targetError && target == Type.recoveryType) { + if (targetError && currentTarget == Type.recoveryType) { //a target error doesn't make sense during recovery stage //as we don't know what actual parameter types are - result = that.type = target; + result = that.type = currentTarget; return; } else { if (targetError) { @@ -2770,7 +2789,7 @@ } else { log.report(diag); } - result = that.type = types.createErrorType(target); + result = that.type = types.createErrorType(currentTarget); return; } } @@ -2781,7 +2800,7 @@ if (desc.getReturnType() == Type.recoveryType) { // stop here - result = that.type = target; + result = that.type = currentTarget; return; } @@ -2799,7 +2818,7 @@ //static ref with class type-args log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()), diags.fragment("static.mref.with.targs")); - result = that.type = types.createErrorType(target); + result = that.type = types.createErrorType(currentTarget); return; } @@ -2808,7 +2827,7 @@ //no static bound mrefs log.error(that.expr.pos(), "invalid.mref", Kinds.kindName(that.getMode()), diags.fragment("static.bound.mref")); - result = that.type = types.createErrorType(target); + result = that.type = types.createErrorType(currentTarget); return; } @@ -2816,19 +2835,24 @@ // Check that super-qualified symbols are not abstract (JLS) rs.checkNonAbstract(that.pos(), that.sym); } + + if (isTargetSerializable) { + chk.checkElemAccessFromSerializableLambda(that); + } } ResultInfo checkInfo = resultInfo.dup(newMethodTemplate( desc.getReturnType().hasTag(VOID) ? Type.noType : desc.getReturnType(), - that.kind.isUnbound() ? argtypes.tail : argtypes, typeargtypes)); + that.kind.isUnbound() ? argtypes.tail : argtypes, typeargtypes), + new FunctionalReturnContext(resultInfo.checkContext)); Type refType = checkId(that, lookupHelper.site, refSym, localEnv, checkInfo); if (that.kind.isUnbound() && resultInfo.checkContext.inferenceContext().free(argtypes.head)) { //re-generate inference constraints for unbound receiver - if (!types.isSubtype(resultInfo.checkContext.inferenceContext().asFree(argtypes.head), exprType)) { + if (!types.isSubtype(resultInfo.checkContext.inferenceContext().asUndetVar(argtypes.head), exprType)) { //cannot happen as this has already been checked - we just need //to regenerate the inference constraints, as that has been lost //as a result of the call to inferenceContext.save() @@ -2847,9 +2871,9 @@ resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound); if (!isSpeculativeRound) { - checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, target); + checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, currentTarget); } - result = check(that, target, VAL, resultInfo); + result = check(that, currentTarget, VAL, resultInfo); } catch (Types.FunctionDescriptorLookupError ex) { JCDiagnostic cause = ex.getDiagnostic(); resultInfo.checkContext.report(that, cause); @@ -2866,7 +2890,7 @@ @SuppressWarnings("fallthrough") void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) { - Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType()); + Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType()); Type resType; switch (tree.getMode()) { @@ -2898,7 +2922,7 @@ } if (!speculativeAttr) { - List<Type> thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes()); + List<Type> thrownTypes = checkContext.inferenceContext().asUndetVars(descriptor.getThrownTypes()); if (chk.unhandled(refType.getThrownTypes(), thrownTypes).nonEmpty()) { log.error(tree, "incompatible.thrown.types.in.mref", refType.getThrownTypes()); } @@ -3009,15 +3033,6 @@ Type ctype = cfolder.fold1(opc, argtype); if (ctype != null) { owntype = cfolder.coerce(ctype, owntype); - - // Remove constant types from arguments to - // conserve space. The parser will fold concatenations - // of string literals; the code here also - // gets rid of intermediate results when some of the - // operands are constant identifiers. - if (tree.arg.type.tsym == syms.stringType.tsym) { - tree.arg.type = syms.stringType; - } } } } @@ -3051,18 +3066,6 @@ Type ctype = cfolder.fold2(opc, left, right); if (ctype != null) { owntype = cfolder.coerce(ctype, owntype); - - // Remove constant types from arguments to - // conserve space. The parser will fold concatenations - // of string literals; the code here also - // gets rid of intermediate results when some of the - // operands are constant identifiers. - if (tree.lhs.type.tsym == syms.stringType.tsym) { - tree.lhs.type = syms.stringType; - } - if (tree.rhs.type.tsym == syms.stringType.tsym) { - tree.rhs.type = syms.stringType; - } } } @@ -3210,6 +3213,11 @@ while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym)) env1 = env1.outer; } + + if (env.info.isSerializable) { + chk.checkElemAccessFromSerializableLambda(tree); + } + result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo); } @@ -3334,6 +3342,10 @@ } } + if (env.info.isSerializable) { + chk.checkElemAccessFromSerializableLambda(tree); + } + env.info.selectSuper = selectSuperPrev; result = checkId(tree, site, sym, env, resultInfo); } @@ -4212,6 +4224,11 @@ ((c.flags_field & (Flags.ENUM | Flags.COMPOUND)) == 0)) { log.error(env.tree.pos(), "enum.types.not.extensible"); } + + if (isSerializable(c.type)) { + env.info.isSerializable = true; + } + attribClassBody(env, c); chk.checkDeprecatedAnnotation(env.tree.pos(), c); @@ -4325,7 +4342,7 @@ // Check for proper use of serialVersionUID if (env.info.lint.isEnabled(LintCategory.SERIAL) && - isSerializable(c) && + isSerializable(c.type) && (c.flags() & Flags.ENUM) == 0 && checkForSerial(c)) { checkSerialVersionUID(tree, c); @@ -4365,15 +4382,15 @@ return null; } - /** check if a class is a subtype of Serializable, if that is available. */ - private boolean isSerializable(ClassSymbol c) { + /** check if a type is a subtype of Serializable, if that is available. */ + boolean isSerializable(Type t) { try { syms.serializableType.complete(); } catch (CompletionFailure e) { return false; } - return types.isSubtype(c.type, syms.serializableType); + return types.isSubtype(t, syms.serializableType); } /** Check that an appropriate serialVersionUID member is defined. */ @@ -4653,10 +4670,19 @@ private void initTypeIfNeeded(JCTree that) { if (that.type == null) { - that.type = syms.unknownType; + if (that.hasTag(METHODDEF)) { + that.type = dummyMethodType(); + } else { + that.type = syms.unknownType; + } } } + private Type dummyMethodType() { + return new MethodType(List.<Type>nil(), syms.unknownType, + List.<Type>nil(), syms.methodClass); + } + @Override public void scan(JCTree tree) { if (tree == null) return; @@ -4712,7 +4738,8 @@ @Override public void visitNewClass(JCNewClass that) { if (that.constructor == null) { - that.constructor = new MethodSymbol(0, names.init, syms.unknownType, syms.noSymbol); + that.constructor = new MethodSymbol(0, names.init, + dummyMethodType(), syms.noSymbol); } if (that.constructorType == null) { that.constructorType = syms.unknownType; @@ -4722,22 +4749,28 @@ @Override public void visitAssignop(JCAssignOp that) { - if (that.operator == null) - that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); + if (that.operator == null) { + that.operator = new OperatorSymbol(names.empty, dummyMethodType(), + -1, syms.noSymbol); + } super.visitAssignop(that); } @Override public void visitBinary(JCBinary that) { - if (that.operator == null) - that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); + if (that.operator == null) { + that.operator = new OperatorSymbol(names.empty, dummyMethodType(), + -1, syms.noSymbol); + } super.visitBinary(that); } @Override public void visitUnary(JCUnary that) { - if (that.operator == null) - that.operator = new OperatorSymbol(names.empty, syms.unknownType, -1, syms.noSymbol); + if (that.operator == null) { + that.operator = new OperatorSymbol(names.empty, dummyMethodType(), + -1, syms.noSymbol); + } super.visitUnary(that); } @@ -4753,7 +4786,8 @@ public void visitReference(JCMemberReference that) { super.visitReference(that); if (that.sym == null) { - that.sym = new MethodSymbol(0, names.empty, syms.unknownType, syms.noSymbol); + that.sym = new MethodSymbol(0, names.empty, dummyMethodType(), + syms.noSymbol); } if (that.targets == null) { that.targets = List.nil();
--- a/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/AttrContext.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -54,6 +54,10 @@ */ boolean selectSuper = false; + /** Is the current target of lambda expression or method reference serializable? + */ + boolean isSerializable = false; + /** Are arguments to current function applications boxed into an array for varargs? */ Resolve.MethodResolutionPhase pendingResolutionPhase = null; @@ -89,6 +93,7 @@ info.enclVar = enclVar; info.returnResult = returnResult; info.defaultSuperCallSite = defaultSuperCallSite; + info.isSerializable = isSerializable; return info; }
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -82,6 +82,7 @@ private final TreeInfo treeinfo; private final JavaFileManager fileManager; private final Profile profile; + private final boolean warnOnAccessToSensitiveMembers; // The set of lint options currently in effect. It is initialized // from the context, and then is set/reset as needed by Attr as it @@ -131,6 +132,7 @@ warnOnSyntheticConflicts = options.isSet("warnOnSyntheticConflicts"); suppressAbortOnBadClassFile = options.isSet("suppressAbortOnBadClassFile"); enableSunApiLintControl = options.isSet("enableSunApiLintControl"); + warnOnAccessToSensitiveMembers = options.isSet("warnOnAccessToSensitiveMembers"); Target target = Target.instance(context); syntheticNameChar = target.syntheticNameChar(); @@ -510,6 +512,11 @@ public DeferredAttrContext deferredAttrContext() { return deferredAttr.emptyDeferredAttrContext; } + + @Override + public String toString() { + return "CheckContext: basicHandler"; + } }; /** Check that a given type is assignable to a given proto-type. @@ -616,7 +623,7 @@ } else if (a.isExtendsBound()) { return types.isCastable(bound, types.upperBound(a), types.noWarnings); } else if (a.isSuperBound()) { - return !types.notSoftSubtype(types.lowerBound(a), bound); + return !types.notSoftSubtype(types.wildLowerBound(a), bound); } return true; } @@ -2583,6 +2590,44 @@ } } + void checkElemAccessFromSerializableLambda(final JCTree tree) { + if (warnOnAccessToSensitiveMembers) { + Symbol sym = TreeInfo.symbol(tree); + if ((sym.kind & (VAR | MTH)) == 0) { + return; + } + + if (sym.kind == VAR) { + if ((sym.flags() & PARAMETER) != 0 || + sym.isLocal() || + sym.name == names._this || + sym.name == names._super) { + return; + } + } + + if (!types.isSubtype(sym.owner.type, syms.serializableType) && + isEffectivelyNonPublic(sym)) { + log.warning(tree.pos(), + "access.to.sensitive.member.from.serializable.element", sym); + } + } + } + + private boolean isEffectivelyNonPublic(Symbol sym) { + if (sym.packge() == syms.rootPackage) { + return false; + } + + while (sym.kind != Kinds.PCK) { + if ((sym.flags() & PUBLIC) == 0) { + return true; + } + sym = sym.owner; + } + return false; + } + /** Report a conflict between a user symbol and a synthetic symbol. */ private void syntheticError(DiagnosticPosition pos, Symbol sym) { @@ -2680,7 +2725,7 @@ if (types.isSameType(type, syms.stringType)) return; if ((type.tsym.flags() & Flags.ENUM) != 0) return; if ((type.tsym.flags() & Flags.ANNOTATION) != 0) return; - if (types.lowerBound(type).tsym == syms.classType.tsym) return; + if (types.cvarLowerBound(type).tsym == syms.classType.tsym) return; if (types.isArray(type) && !types.isArray(types.elemtype(type))) { validateAnnotationType(pos, types.elemtype(type)); return; @@ -2779,7 +2824,7 @@ validateDocumented(t.tsym, s, pos); validateInherited(t.tsym, s, pos); validateTarget(t.tsym, s, pos); - validateDefault(t.tsym, s, pos); + validateDefault(t.tsym, pos); } private void validateValue(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) { @@ -2898,7 +2943,9 @@ /** Checks that s is a subset of t, with respect to ElementType - * semantics, specifically {ANNOTATION_TYPE} is a subset of {TYPE} + * semantics, specifically {ANNOTATION_TYPE} is a subset of {TYPE}, + * and {TYPE_USE} covers the set {ANNOTATION_TYPE, TYPE, TYPE_USE, + * TYPE_PARAMETER}. */ private boolean isTargetSubsetOf(Set<Name> s, Set<Name> t) { // Check that all elements in s are present in t @@ -2911,6 +2958,12 @@ } else if (n1 == names.TYPE && n2 == names.ANNOTATION_TYPE) { currentElementOk = true; break; + } else if (n1 == names.TYPE_USE && + (n2 == names.TYPE || + n2 == names.ANNOTATION_TYPE || + n2 == names.TYPE_PARAMETER)) { + currentElementOk = true; + break; } } if (!currentElementOk) @@ -2919,7 +2972,7 @@ return true; } - private void validateDefault(Symbol container, Symbol contained, DiagnosticPosition pos) { + private void validateDefault(Symbol container, DiagnosticPosition pos) { // validate that all other elements of containing type has defaults Scope scope = container.members(); for(Symbol elm : scope.getElements()) {
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,7 @@ package com.sun.tools.javac.comp; -import com.sun.source.tree.MemberReferenceTree; +import com.sun.source.tree.LambdaExpressionTree.BodyKind; import com.sun.tools.javac.code.*; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.util.*; @@ -35,10 +35,8 @@ import com.sun.tools.javac.comp.Attr.ResultInfo; import com.sun.tools.javac.comp.Infer.InferenceContext; import com.sun.tools.javac.comp.Resolve.MethodResolutionPhase; -import com.sun.tools.javac.comp.Resolve.ReferenceLookupHelper; import com.sun.tools.javac.tree.JCTree.*; - import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; @@ -48,6 +46,7 @@ import java.util.Set; import java.util.WeakHashMap; +import static com.sun.tools.javac.code.Kinds.VAL; import static com.sun.tools.javac.code.TypeTag.*; import static com.sun.tools.javac.tree.JCTree.Tag.*; @@ -76,6 +75,8 @@ final Symtab syms; final TreeMaker make; final Types types; + final Flow flow; + final Names names; public static DeferredAttr instance(Context context) { DeferredAttr instance = context.get(deferredAttrKey); @@ -96,7 +97,8 @@ syms = Symtab.instance(context); make = TreeMaker.instance(context); types = Types.instance(context); - Names names = Names.instance(context); + flow = Flow.instance(context); + names = Names.instance(context); stuckTree = make.Ident(names.empty).setType(Type.stuckType); emptyDeferredAttrContext = new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { @@ -108,6 +110,11 @@ void complete() { Assert.error("Empty deferred context!"); } + + @Override + public String toString() { + return "Empty deferred context!"; + } }; } @@ -139,6 +146,11 @@ return DEFERRED; } + @Override + public String toString() { + return "DeferredType"; + } + /** * A speculative cache is used to keep track of all overload resolution rounds * that triggered speculative attribution on a given deferred type. Each entry @@ -378,7 +390,9 @@ } } //where - protected TreeScanner unenterScanner = new TreeScanner() { + protected UnenterScanner unenterScanner = new UnenterScanner(); + + class UnenterScanner extends TreeScanner { @Override public void visitClassDef(JCClassDecl tree) { ClassSymbol csym = tree.sym; @@ -391,7 +405,7 @@ syms.classes.remove(csym.flatname); super.visitClassDef(tree); } - }; + } /** * A deferred context is created on each method check. A deferred context is @@ -595,19 +609,111 @@ public void visitLambda(JCLambda tree) { Check.CheckContext checkContext = resultInfo.checkContext; Type pt = resultInfo.pt; - if (inferenceContext.inferencevars.contains(pt)) { - //ok - return; - } else { + if (!inferenceContext.inferencevars.contains(pt)) { //must be a functional descriptor + Type descriptorType = null; try { - Type desc = types.findDescriptorType(pt); - if (desc.getParameterTypes().length() != tree.params.length()) { - checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda")); - } + descriptorType = types.findDescriptorType(pt); } catch (Types.FunctionDescriptorLookupError ex) { checkContext.report(null, ex.getDiagnostic()); } + + if (descriptorType.getParameterTypes().length() != tree.params.length()) { + checkContext.report(tree, + diags.fragment("incompatible.arg.types.in.lambda")); + } + + Type currentReturnType = descriptorType.getReturnType(); + boolean returnTypeIsVoid = currentReturnType.hasTag(VOID); + if (tree.getBodyKind() == BodyKind.EXPRESSION) { + boolean isExpressionCompatible = !returnTypeIsVoid || + TreeInfo.isExpressionStatement((JCExpression)tree.getBody()); + if (!isExpressionCompatible) { + resultInfo.checkContext.report(tree.pos(), + diags.fragment("incompatible.ret.type.in.lambda", + diags.fragment("missing.ret.val", currentReturnType))); + } + } else { + LambdaBodyStructChecker lambdaBodyChecker = + new LambdaBodyStructChecker(); + + tree.body.accept(lambdaBodyChecker); + boolean isVoidCompatible = lambdaBodyChecker.isVoidCompatible; + + if (returnTypeIsVoid) { + if (!isVoidCompatible) { + resultInfo.checkContext.report(tree.pos(), + diags.fragment("unexpected.ret.val")); + } + } else { + boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible + && !canLambdaBodyCompleteNormally(tree); + if (!isValueCompatible && !isVoidCompatible) { + log.error(tree.body.pos(), + "lambda.body.neither.value.nor.void.compatible"); + } + + if (!isValueCompatible) { + resultInfo.checkContext.report(tree.pos(), + diags.fragment("incompatible.ret.type.in.lambda", + diags.fragment("missing.ret.val", currentReturnType))); + } + } + } + } + } + + boolean canLambdaBodyCompleteNormally(JCLambda tree) { + JCLambda newTree = new TreeCopier<>(make).copy(tree); + /* attr.lambdaEnv will create a meaningful env for the + * lambda expression. This is specially useful when the + * lambda is used as the init of a field. But we need to + * remove any added symbol. + */ + Env<AttrContext> localEnv = attr.lambdaEnv(newTree, env); + try { + List<JCVariableDecl> tmpParams = newTree.params; + while (tmpParams.nonEmpty()) { + tmpParams.head.vartype = make.at(tmpParams.head).Type(syms.errType); + tmpParams = tmpParams.tail; + } + + attr.attribStats(newTree.params, localEnv); + + /* set pt to Type.noType to avoid generating any bound + * which may happen if lambda's return type is an + * inference variable + */ + Attr.ResultInfo bodyResultInfo = attr.new ResultInfo(VAL, Type.noType); + localEnv.info.returnResult = bodyResultInfo; + + // discard any log output + Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); + try { + JCBlock body = (JCBlock)newTree.body; + /* we need to attribute the lambda body before + * doing the aliveness analysis. This is because + * constant folding occurs during attribution + * and the reachability of some statements depends + * on constant values, for example: + * + * while (true) {...} + */ + attr.attribStats(body.stats, localEnv); + + attr.preFlow(newTree); + /* make an aliveness / reachability analysis of the lambda + * to determine if it can complete normally + */ + flow.analyzeLambda(localEnv, newTree, make, true); + } finally { + log.popDiagnosticHandler(diagHandler); + } + return newTree.canCompleteNormally; + } finally { + JCBlock body = (JCBlock)newTree.body; + unenterScanner.scan(body.stats); + localEnv.info.scope.leave(); } } @@ -625,10 +731,7 @@ public void visitReference(JCMemberReference tree) { Check.CheckContext checkContext = resultInfo.checkContext; Type pt = resultInfo.pt; - if (inferenceContext.inferencevars.contains(pt)) { - //ok - return; - } else { + if (!inferenceContext.inferencevars.contains(pt)) { try { types.findDescriptorType(pt); } catch (Types.FunctionDescriptorLookupError ex) { @@ -658,6 +761,40 @@ } } } + + /* This visitor looks for return statements, its analysis will determine if + * a lambda body is void or value compatible. We must analyze return + * statements contained in the lambda body only, thus any return statement + * contained in an inner class or inner lambda body, should be ignored. + */ + class LambdaBodyStructChecker extends TreeScanner { + boolean isVoidCompatible = true; + boolean isPotentiallyValueCompatible = true; + + @Override + public void visitClassDef(JCClassDecl tree) { + // do nothing + } + + @Override + public void visitLambda(JCLambda tree) { + // do nothing + } + + @Override + public void visitNewClass(JCNewClass tree) { + // do nothing + } + + @Override + public void visitReturn(JCReturn tree) { + if (tree.expr != null) { + isVoidCompatible = false; + } else { + isPotentiallyValueCompatible = false; + } + } + } } /** an empty deferred attribution context - all methods throw exceptions */ @@ -769,7 +906,7 @@ /** * handler that is executed when a node has been discarded */ - abstract void skip(JCTree tree); + void skip(JCTree tree) {} } /** @@ -781,11 +918,6 @@ PolyScanner() { super(EnumSet.of(CONDEXPR, PARENS, LAMBDA, REFERENCE)); } - - @Override - void skip(JCTree tree) { - //do nothing - } } /** @@ -798,11 +930,6 @@ super(EnumSet.of(BLOCK, CASE, CATCH, DOLOOP, FOREACHLOOP, FORLOOP, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP)); } - - @Override - void skip(JCTree tree) { - //do nothing - } } /**
--- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,7 +45,7 @@ import static com.sun.tools.javac.tree.JCTree.Tag.*; /** This pass implements dataflow analysis for Java programs though - * different AST visitor steps. Liveness analysis (see AliveAlanyzer) checks that + * different AST visitor steps. Liveness analysis (see AliveAnalyzer) checks that * every statement is reachable. Exception analysis (see FlowAnalyzer) ensures that * every checked exception that is thrown is declared or caught. Definite assignment analysis * (see AssignAnalyzer) ensures that each variable is assigned when used. Definite @@ -197,6 +197,7 @@ private final boolean allowImprovedRethrowAnalysis; private final boolean allowImprovedCatchAnalysis; private final boolean allowEffectivelyFinalInInnerClasses; + private final boolean enforceThisDotInit; public static Flow instance(Context context) { Flow instance = context.get(flowKey); @@ -207,7 +208,7 @@ public void analyzeTree(Env<AttrContext> env, TreeMaker make) { new AliveAnalyzer().analyzeTree(env, make); - new AssignAnalyzer(log, syms, lint, names).analyzeTree(env); + new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit).analyzeTree(env); new FlowAnalyzer().analyzeTree(env, make); new CaptureAnalyzer().analyzeTree(env, make); } @@ -239,7 +240,7 @@ //related errors, which will allow for more errors to be detected Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); try { - new AssignAnalyzer(log, syms, lint, names).analyzeTree(env); + new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit).analyzeTree(env); LambdaFlowAnalyzer flowAnalyzer = new LambdaFlowAnalyzer(); flowAnalyzer.analyzeTree(env, that, make); return flowAnalyzer.inferredThrownTypes; @@ -289,6 +290,7 @@ allowImprovedRethrowAnalysis = source.allowImprovedRethrowAnalysis(); allowImprovedCatchAnalysis = source.allowImprovedCatchAnalysis(); allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses(); + enforceThisDotInit = source.enforceThisDotInit(); } /** @@ -1427,6 +1429,8 @@ protected Names names; + final boolean enforceThisDotInit; + public static class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit { final Bits inits; @@ -1449,7 +1453,7 @@ } } - public AbstractAssignAnalyzer(Bits inits, Symtab syms, Names names) { + public AbstractAssignAnalyzer(Bits inits, Symtab syms, Names names, boolean enforceThisDotInit) { this.inits = inits; uninits = new Bits(); uninitsTry = new Bits(); @@ -1459,11 +1463,22 @@ uninitsWhenFalse = new Bits(true); this.syms = syms; this.names = names; + this.enforceThisDotInit = enforceThisDotInit; } + private boolean isInitialConstructor = false; + @Override protected void markDead(JCTree tree) { - inits.inclRange(returnadr, nextadr); + if (!isInitialConstructor) { + inits.inclRange(returnadr, nextadr); + } else { + for (int address = returnadr; address < nextadr; address++) { + if (!(isFinalUninitializedStaticField(vardecls[address].sym))) { + inits.incl(address); + } + } + } uninits.inclRange(returnadr, nextadr); } @@ -1476,8 +1491,17 @@ return sym.pos >= startPos && ((sym.owner.kind == MTH || - ((sym.flags() & (FINAL | HASINIT | PARAMETER)) == FINAL && - classDef.sym.isEnclosedBy((ClassSymbol)sym.owner)))); + isFinalUninitializedField(sym))); + } + + boolean isFinalUninitializedField(VarSymbol sym) { + return sym.owner.kind == TYP && + ((sym.flags() & (FINAL | HASINIT | PARAMETER)) == FINAL && + classDef.sym.isEnclosedBy((ClassSymbol)sym.owner)); + } + + boolean isFinalUninitializedStaticField(VarSymbol sym) { + return isFinalUninitializedField(sym) && sym.isStatic(); } /** Initialize new trackable variable by setting its address field @@ -1731,10 +1755,9 @@ int returnadrPrev = returnadr; Assert.check(pendingExits.isEmpty()); - + boolean lastInitialConstructor = isInitialConstructor; try { - boolean isInitialConstructor = - TreeInfo.isInitialConstructor(tree); + isInitialConstructor = TreeInfo.isInitialConstructor(tree); if (!isInitialConstructor) { firstadr = nextadr; @@ -1789,6 +1812,7 @@ nextadr = nextadrPrev; firstadr = firstadrPrev; returnadr = returnadrPrev; + isInitialConstructor = lastInitialConstructor; } } @@ -2261,12 +2285,34 @@ public void visitAssign(JCAssign tree) { JCTree lhs = TreeInfo.skipParens(tree.lhs); - if (!(lhs instanceof JCIdent)) { + if (!isIdentOrThisDotIdent(lhs)) scanExpr(lhs); - } scanExpr(tree.rhs); letInit(lhs); } + private boolean isIdentOrThisDotIdent(JCTree lhs) { + if (lhs.hasTag(IDENT)) + return true; + if (!lhs.hasTag(SELECT)) + return false; + + JCFieldAccess fa = (JCFieldAccess)lhs; + return fa.selected.hasTag(IDENT) && + ((JCIdent)fa.selected).name == names._this; + } + + // check fields accessed through this.<field> are definitely + // assigned before reading their value + public void visitSelect(JCFieldAccess tree) { + super.visitSelect(tree); + if (enforceThisDotInit && + tree.selected.hasTag(IDENT) && + ((JCIdent)tree.selected).name == names._this && + tree.sym.kind == VAR) + { + checkInit(tree.pos(), (VarSymbol)tree.sym); + } + } public void visitAssignop(JCAssignOp tree) { scanExpr(tree.lhs); @@ -2400,8 +2446,8 @@ } } - public AssignAnalyzer(Log log, Symtab syms, Lint lint, Names names) { - super(new Bits(), syms, names); + public AssignAnalyzer(Log log, Symtab syms, Lint lint, Names names, boolean enforceThisDotInit) { + super(new Bits(), syms, names, enforceThisDotInit); this.log = log; this.lint = lint; }
--- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -142,24 +142,24 @@ * Main inference entry point - instantiate a generic method type * using given argument types and (possibly) an expected target-type. */ - public Type instantiateMethod(Env<AttrContext> env, - List<Type> tvars, - MethodType mt, - Attr.ResultInfo resultInfo, - Symbol msym, - List<Type> argtypes, - boolean allowBoxing, - boolean useVarargs, - Resolve.MethodResolutionContext resolveContext, - Warner warn) throws InferenceException { + Type instantiateMethod( Env<AttrContext> env, + List<Type> tvars, + MethodType mt, + Attr.ResultInfo resultInfo, + MethodSymbol msym, + List<Type> argtypes, + boolean allowBoxing, + boolean useVarargs, + Resolve.MethodResolutionContext resolveContext, + Warner warn) throws InferenceException { //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG - final InferenceContext inferenceContext = new InferenceContext(tvars); + final InferenceContext inferenceContext = new InferenceContext(tvars); //B0 inferenceException.clear(); try { DeferredAttr.DeferredAttrContext deferredAttrContext = resolveContext.deferredAttrContext(msym, inferenceContext, resultInfo, warn); - resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext, + resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext, //B2 argtypes, mt.getParameterTypes(), warn); if (allowGraphInference && @@ -167,7 +167,8 @@ !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) { //inject return constraints earlier checkWithinBounds(inferenceContext, warn); //propagation - Type newRestype = generateReturnConstraints(resultInfo, mt, inferenceContext); + Type newRestype = generateReturnConstraints(env.tree, resultInfo, //B3 + mt, inferenceContext); mt = (MethodType)types.createMethodTypeWithReturn(mt, newRestype); //propagate outwards if needed if (resultInfo.checkContext.inferenceContext().free(resultInfo.pt)) { @@ -193,7 +194,7 @@ inferenceContext.restvars().nonEmpty() && resultInfo != null && !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) { - generateReturnConstraints(resultInfo, mt, inferenceContext); + generateReturnConstraints(env.tree, resultInfo, mt, inferenceContext); inferenceContext.solveLegacy(false, warn, LegacyInferenceSteps.EQ_UPPER.steps); //maximizeInst mt = (MethodType)inferenceContext.asInstType(mt); } @@ -210,6 +211,12 @@ } else { inferenceContext.notifyChange(inferenceContext.boundedVars()); } + if (resultInfo == null) { + /* if the is no result info then we can clear the capture types + * cache without affecting any result info check + */ + inferenceContext.captureTypeCache.clear(); + } } } @@ -218,11 +225,12 @@ * call occurs in a context where a type T is expected, use the expected * type to derive more constraints on the generic method inference variables. */ - Type generateReturnConstraints(Attr.ResultInfo resultInfo, + Type generateReturnConstraints(JCTree tree, Attr.ResultInfo resultInfo, MethodType mt, InferenceContext inferenceContext) { + InferenceContext rsInfoInfContext = resultInfo.checkContext.inferenceContext(); Type from = mt.getReturnType(); if (mt.getReturnType().containsAny(inferenceContext.inferencevars) && - resultInfo.checkContext.inferenceContext() != emptyContext) { + rsInfoInfContext != emptyContext) { from = types.capture(from); //add synthetic captured ivars for (Type t : from.getTypeArguments()) { @@ -231,13 +239,29 @@ } } } - Type qtype1 = inferenceContext.asFree(from); - Type to = returnConstraintTarget(qtype1, resultInfo.pt); - Assert.check(allowGraphInference || !resultInfo.checkContext.inferenceContext().free(to), + Type qtype = inferenceContext.asUndetVar(from); + Type to = resultInfo.pt; + + if (qtype.hasTag(VOID)) { + to = syms.voidType; + } else if (to.hasTag(NONE)) { + to = from.isPrimitive() ? from : syms.objectType; + } else if (qtype.hasTag(UNDETVAR)) { + if (resultInfo.pt.isReference()) { + to = generateReturnConstraintsUndetVarToReference( + tree, (UndetVar)qtype, to, resultInfo, inferenceContext); + } else { + if (to.isPrimitive()) { + to = generateReturnConstraintsPrimitive(tree, (UndetVar)qtype, to, + resultInfo, inferenceContext); + } + } + } + Assert.check(allowGraphInference || !rsInfoInfContext.free(to), "legacy inference engine cannot handle constraints on both sides of a subtyping assertion"); //we need to skip capture? Warner retWarn = new Warner(); - if (!resultInfo.checkContext.compatible(qtype1, resultInfo.checkContext.inferenceContext().asFree(to), retWarn) || + if (!resultInfo.checkContext.compatible(qtype, rsInfoInfContext.asUndetVar(to), retWarn) || //unchecked conversion is not allowed in source 7 mode (!allowGraphInference && retWarn.hasLint(Lint.LintCategory.UNCHECKED))) { throw inferenceException @@ -247,30 +271,96 @@ return from; } - Type returnConstraintTarget(Type from, Type to) { - if (from.hasTag(VOID)) { - return syms.voidType; - } else if (to.hasTag(NONE)) { - return from.isPrimitive() ? from : syms.objectType; - } else if (from.hasTag(UNDETVAR) && to.isPrimitive()) { - if (!allowGraphInference) { - //if legacy, just return boxed type - return types.boxedClass(to).type; + private Type generateReturnConstraintsPrimitive(JCTree tree, UndetVar from, + Type to, Attr.ResultInfo resultInfo, InferenceContext inferenceContext) { + if (!allowGraphInference) { + //if legacy, just return boxed type + return types.boxedClass(to).type; + } + //if graph inference we need to skip conflicting boxed bounds... + for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.UPPER, + InferenceBound.LOWER)) { + Type boundAsPrimitive = types.unboxedType(t); + if (boundAsPrimitive == null || boundAsPrimitive.hasTag(NONE)) { + continue; } - //if graph inference we need to skip conflicting boxed bounds... - UndetVar uv = (UndetVar)from; - for (Type t : uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) { - Type boundAsPrimitive = types.unboxedType(t); - if (boundAsPrimitive == null) continue; - if (types.isConvertible(boundAsPrimitive, to)) { - //effectively skip return-type constraint generation (compatibility) - return syms.objectType; + return generateReferenceToTargetConstraint(tree, from, to, + resultInfo, inferenceContext); + } + return types.boxedClass(to).type; + } + + private Type generateReturnConstraintsUndetVarToReference(JCTree tree, + UndetVar from, Type to, Attr.ResultInfo resultInfo, + InferenceContext inferenceContext) { + Type captureOfTo = types.capture(to); + /* T is a reference type, but is not a wildcard-parameterized type, and either + */ + if (captureOfTo == to) { //not a wildcard parameterized type + /* i) B2 contains a bound of one of the forms alpha = S or S <: alpha, + * where S is a wildcard-parameterized type, or + */ + for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) { + Type captureOfBound = types.capture(t); + if (captureOfBound != t) { + return generateReferenceToTargetConstraint(tree, from, to, + resultInfo, inferenceContext); } } - return types.boxedClass(to).type; - } else { - return to; + + /* ii) B2 contains two bounds of the forms S1 <: alpha and S2 <: alpha, + * where S1 and S2 have supertypes that are two different + * parameterizations of the same generic class or interface. + */ + for (Type aLowerBound : from.getBounds(InferenceBound.LOWER)) { + for (Type anotherLowerBound : from.getBounds(InferenceBound.LOWER)) { + if (aLowerBound != anotherLowerBound && + commonSuperWithDiffParameterization(aLowerBound, anotherLowerBound)) { + /* self comment check if any lower bound may be and undetVar, + * in that case the result of this call may be a false positive. + * Should this be restricted to non free types? + */ + return generateReferenceToTargetConstraint(tree, from, to, + resultInfo, inferenceContext); + } + } + } } + + /* T is a parameterization of a generic class or interface, G, + * and B2 contains a bound of one of the forms alpha = S or S <: alpha, + * where there exists no type of the form G<...> that is a + * supertype of S, but the raw type G is a supertype of S + */ + if (to.isParameterized()) { + for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) { + Type sup = types.asSuper(t, to.tsym); + if (sup != null && sup.isRaw()) { + return generateReferenceToTargetConstraint(tree, from, to, + resultInfo, inferenceContext); + } + } + } + return to; + } + + private boolean commonSuperWithDiffParameterization(Type t, Type s) { + Pair<Type, Type> supers = getParameterizedSupers(t, s); + return (supers != null && !types.isSameType(supers.fst, supers.snd)); + } + + private Type generateReferenceToTargetConstraint(JCTree tree, UndetVar from, + Type to, Attr.ResultInfo resultInfo, + InferenceContext inferenceContext) { + inferenceContext.solve(List.of(from.qtype), new Warner()); + Type capturedType = resultInfo.checkContext.inferenceContext() + .cachedCapture(tree, from.inst, false); + if (types.isConvertible(capturedType, + resultInfo.checkContext.inferenceContext().asUndetVar(to))) { + //effectively skip additional return-type constraint generation (compatibility) + return syms.objectType; + } + return to; } /** @@ -280,7 +370,7 @@ ListBuffer<Type> todo = new ListBuffer<>(); //step 1 - create fresh tvars for (Type t : vars) { - UndetVar uv = (UndetVar)inferenceContext.asFree(t); + UndetVar uv = (UndetVar)inferenceContext.asUndetVar(t); List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER); if (Type.containsAny(upperBounds, vars)) { TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); @@ -399,7 +489,7 @@ return types.createErrorType(funcInterface); } for (Type p : descParameterTypes) { - if (!types.isSameType(funcInterfaceContext.asFree(p), paramTypes.head)) { + if (!types.isSameType(funcInterfaceContext.asUndetVar(p), paramTypes.head)) { checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface)); return types.createErrorType(funcInterface); } @@ -515,6 +605,32 @@ /** max number of incorporation rounds */ static final int MAX_INCORPORATION_STEPS = 100; + /* If for two types t and s there is a least upper bound that is a + * parameterized type G, then there exists a supertype of 't' of the form + * G<T1, ..., Tn> and a supertype of 's' of the form G<S1, ..., Sn> + * which will be returned by this method. If no such supertypes exists then + * null is returned. + * + * As an example for the following input: + * + * t = java.util.ArrayList<java.lang.String> + * s = java.util.List<T> + * + * we get this ouput: + * + * Pair[java.util.List<java.lang.String>,java.util.List<T>] + */ + private Pair<Type, Type> getParameterizedSupers(Type t, Type s) { + Type lubResult = types.lub(t, s); + if (lubResult == syms.errType || lubResult == syms.botType || + !lubResult.isParameterized()) { + return null; + } + Type asSuperOfT = types.asSuper(t, lubResult.tsym); + Type asSuperOfS = types.asSuper(s, lubResult.tsym); + return new Pair<>(asSuperOfT, asSuperOfS); + } + /** * This enumeration defines an entry point for doing inference variable * bound incorporation - it can be used to inject custom incorporation @@ -533,22 +649,23 @@ if (uv.inst != null) { Type inst = uv.inst; for (Type u : uv.getBounds(InferenceBound.UPPER)) { - if (!isSubtype(inst, inferenceContext.asFree(u), warn, infer)) { + if (!isSubtype(inst, inferenceContext.asUndetVar(u), warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.UPPER); } } for (Type l : uv.getBounds(InferenceBound.LOWER)) { - if (!isSubtype(inferenceContext.asFree(l), inst, warn, infer)) { + if (!isSubtype(inferenceContext.asUndetVar(l), inst, warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.LOWER); } } for (Type e : uv.getBounds(InferenceBound.EQ)) { - if (!isSameType(inst, inferenceContext.asFree(e), infer)) { + if (!isSameType(inst, inferenceContext.asUndetVar(e), infer)) { infer.reportBoundError(uv, BoundErrorKind.EQ); } } } } + @Override boolean accepts(UndetVar uv, InferenceContext inferenceContext) { //applies to all undetvars @@ -594,12 +711,12 @@ for (Type e : uv.getBounds(InferenceBound.EQ)) { if (e.containsAny(inferenceContext.inferenceVars())) continue; for (Type u : uv.getBounds(InferenceBound.UPPER)) { - if (!isSubtype(e, inferenceContext.asFree(u), warn, infer)) { + if (!isSubtype(e, inferenceContext.asUndetVar(u), warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER); } } for (Type l : uv.getBounds(InferenceBound.LOWER)) { - if (!isSubtype(inferenceContext.asFree(l), e, warn, infer)) { + if (!isSubtype(inferenceContext.asUndetVar(l), e, warn, infer)) { infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER); } } @@ -615,7 +732,7 @@ Infer infer = inferenceContext.infer(); for (Type b1 : uv.getBounds(InferenceBound.UPPER)) { for (Type b2 : uv.getBounds(InferenceBound.LOWER)) { - isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn , infer); + isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn , infer); } } } @@ -629,7 +746,7 @@ Infer infer = inferenceContext.infer(); for (Type b1 : uv.getBounds(InferenceBound.UPPER)) { for (Type b2 : uv.getBounds(InferenceBound.EQ)) { - isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer); + isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer); } } } @@ -643,12 +760,59 @@ Infer infer = inferenceContext.infer(); for (Type b1 : uv.getBounds(InferenceBound.EQ)) { for (Type b2 : uv.getBounds(InferenceBound.LOWER)) { - isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer); + isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer); } } } }, /** + * Given a bound set containing {@code alpha <: P<T>} and + * {@code alpha <: P<S>} where P is a parameterized type, + * perform {@code T = S} (which could lead to new bounds). + */ + CROSS_UPPER_UPPER() { + @Override + public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { + Infer infer = inferenceContext.infer(); + List<Type> boundList = uv.getBounds(InferenceBound.UPPER); + List<Type> boundListTail = boundList.tail; + while (boundList.nonEmpty()) { + List<Type> tmpTail = boundListTail; + while (tmpTail.nonEmpty()) { + Type b1 = boundList.head; + Type b2 = tmpTail.head; + if (b1 != b2) { + Pair<Type, Type> commonSupers = infer.getParameterizedSupers(b1, b2); + if (commonSupers != null) { + List<Type> allParamsSuperBound1 = commonSupers.fst.allparams(); + List<Type> allParamsSuperBound2 = commonSupers.snd.allparams(); + while (allParamsSuperBound1.nonEmpty() && allParamsSuperBound2.nonEmpty()) { + //traverse the list of all params comparing them + if (!allParamsSuperBound1.head.hasTag(WILDCARD) && + !allParamsSuperBound2.head.hasTag(WILDCARD)) { + isSameType(inferenceContext.asUndetVar(allParamsSuperBound1.head), + inferenceContext.asUndetVar(allParamsSuperBound2.head), infer); + } + allParamsSuperBound1 = allParamsSuperBound1.tail; + allParamsSuperBound2 = allParamsSuperBound2.tail; + } + Assert.check(allParamsSuperBound1.isEmpty() && allParamsSuperBound2.isEmpty()); + } + } + tmpTail = tmpTail.tail; + } + boundList = boundList.tail; + boundListTail = boundList.tail; + } + } + + @Override + boolean accepts(UndetVar uv, InferenceContext inferenceContext) { + return !uv.isCaptured() && + uv.getBounds(InferenceBound.UPPER).nonEmpty(); + } + }, + /** * Given a bound set containing {@code alpha == S} and {@code alpha == T} * perform {@code S == T} (which could lead to new bounds). */ @@ -658,7 +822,7 @@ for (Type b1 : uv.getBounds(InferenceBound.EQ)) { for (Type b2 : uv.getBounds(InferenceBound.EQ)) { if (b1 != b2) { - isSameType(inferenceContext.asFree(b2), inferenceContext.asFree(b1), infer); + isSameType(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), infer); } } } @@ -673,7 +837,7 @@ Infer infer = inferenceContext.infer(); for (Type b : uv.getBounds(InferenceBound.UPPER)) { if (inferenceContext.inferenceVars().contains(b)) { - UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); + UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); if (uv2.isCaptured()) continue; //alpha <: beta //0. set beta :> alpha @@ -699,7 +863,7 @@ Infer infer = inferenceContext.infer(); for (Type b : uv.getBounds(InferenceBound.LOWER)) { if (inferenceContext.inferenceVars().contains(b)) { - UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); + UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); if (uv2.isCaptured()) continue; //alpha :> beta //0. set beta <: alpha @@ -725,7 +889,7 @@ Infer infer = inferenceContext.infer(); for (Type b : uv.getBounds(InferenceBound.EQ)) { if (inferenceContext.inferenceVars().contains(b)) { - UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); + UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); if (uv2.isCaptured()) continue; //alpha == beta //0. set beta == alpha @@ -1243,7 +1407,7 @@ Type solve(UndetVar uv, InferenceContext inferenceContext) { Infer infer = inferenceContext.infer(); List<Type> hibounds = filterBounds(uv, inferenceContext); - //note: lobounds should have at least one element + //note: hibounds should have at least one element Type owntype = hibounds.tail.tail == null ? hibounds.head : infer.types.glb(hibounds); if (owntype.isPrimitive() || owntype.hasTag(ERROR)) { throw infer.inferenceException @@ -1475,7 +1639,7 @@ StringBuilder buf = new StringBuilder(); String sep = ""; for (Type from : data) { - UndetVar uv = (UndetVar)inferenceContext.asFree(from); + UndetVar uv = (UndetVar)inferenceContext.asUndetVar(from); for (Type bound : uv.getBounds(InferenceBound.values())) { if (bound.containsAny(List.from(to.data))) { buf.append(sep); @@ -1684,7 +1848,7 @@ Set<Type> optDepsByNode = stuckDeps.get(i); for (Node n_j : nodes) { Type j = n_j.data.first(); - UndetVar uv_i = (UndetVar)inferenceContext.asFree(i); + UndetVar uv_i = (UndetVar)inferenceContext.asUndetVar(i); if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) { //update i's bound dependencies n_i.addDependency(DependencyKind.BOUND, n_j); @@ -1833,6 +1997,8 @@ }); } + /* Returns the corresponding inference variables. + */ private List<Type> filterVars(Filter<UndetVar> fu) { ListBuffer<Type> res = new ListBuffer<>(); for (Type t : undetvars) { @@ -1890,14 +2056,14 @@ * undet vars (used ahead of subtyping/compatibility checks to allow propagation * of inference constraints). */ - final Type asFree(Type t) { + final Type asUndetVar(Type t) { return types.subst(t, inferencevars, undetvars); } - final List<Type> asFree(List<Type> ts) { + final List<Type> asUndetVars(List<Type> ts) { ListBuffer<Type> buf = new ListBuffer<>(); for (Type t : ts) { - buf.append(asFree(t)); + buf.append(asUndetVar(t)); } return buf.toList(); } @@ -2005,8 +2171,10 @@ * Copy variable in this inference context to the given context */ void dupTo(final InferenceContext that) { - that.inferencevars = that.inferencevars.appendList(inferencevars); - that.undetvars = that.undetvars.appendList(undetvars); + that.inferencevars = that.inferencevars.appendList( + inferencevars.diff(that.inferencevars)); + that.undetvars = that.undetvars.appendList( + undetvars.diff(that.undetvars)); //set up listeners to notify original inference contexts as //propagated vars are inferred in new context for (Type t : inferencevars) { @@ -2073,7 +2241,7 @@ private boolean solveBasic(List<Type> varsToSolve, EnumSet<InferenceStep> steps) { boolean changed = false; for (Type t : varsToSolve.intersect(restvars())) { - UndetVar uv = (UndetVar)asFree(t); + UndetVar uv = (UndetVar)asUndetVar(t); for (InferenceStep step : steps) { if (step.accepts(uv, this)) { uv.inst = step.solve(uv, this); @@ -2119,6 +2287,36 @@ //back-door to infer return Infer.this; } + + @Override + public String toString() { + return "Inference vars: " + inferencevars + '\n' + + "Undet vars: " + undetvars; + } + + /* Method Types.capture() generates a new type every time it's applied + * to a wildcard parameterized type. This is intended functionality but + * there are some cases when what you need is not to generate a new + * captured type but to check that a previously generated captured type + * is correct. There are cases when caching a captured type for later + * reuse is sound. In general two captures from the same AST are equal. + * This is why the tree is used as the key of the map below. This map + * stores a Type per AST. + */ + Map<JCTree, Type> captureTypeCache = new HashMap<>(); + + Type cachedCapture(JCTree tree, Type t, boolean readOnly) { + Type captured = captureTypeCache.get(tree); + if (captured != null) { + return captured; + } + + Type result = types.capture(t); + if (result != t && !readOnly) { // then t is a wildcard parameterized type + captureTypeCache.put(tree, result); + } + return result; + } } final InferenceContext emptyContext = new InferenceContext(List.<Type>nil());
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,7 @@ import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; +import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol; import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type; @@ -50,8 +51,10 @@ import java.util.EnumMap; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import static com.sun.tools.javac.comp.LambdaToMethod.LambdaSymbolKind.*; import static com.sun.tools.javac.code.Flags.*; @@ -96,6 +99,9 @@ /** dump statistics about lambda code generation */ private boolean dumpLambdaToMethodStats; + /** force serializable representation, for stress testing **/ + private final boolean forceSerializable; + /** Flag for alternate metafactories indicating the lambda object is intended to be serializable */ public static final int FLAG_SERIALIZABLE = 1 << 0; @@ -131,6 +137,7 @@ Options options = Options.instance(context); dumpLambdaToMethodStats = options.isSet("dumpLambdaToMethodStats"); attr = Attr.instance(context); + forceSerializable = options.isSet("forceSerializable"); } // </editor-fold> @@ -434,13 +441,9 @@ public void visitVarDef(JCVariableDecl tree) { LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context; if (context != null && lambdaContext.getSymbolMap(LOCAL_VAR).containsKey(tree.sym)) { - JCExpression init = translate(tree.init); - int prevPos = make.pos; - try { - result = make.at(tree).VarDef((VarSymbol)lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym), init); - } finally { - make.at(prevPos); - } + tree.init = translate(tree.init); + tree.sym = (VarSymbol) lambdaContext.getSymbolMap(LOCAL_VAR).get(tree.sym); + result = tree; } else if (context != null && lambdaContext.getSymbolMap(TYPE_VAR).containsKey(tree.sym)) { JCExpression init = translate(tree.init); VarSymbol xsym = (VarSymbol)lambdaContext.getSymbolMap(TYPE_VAR).get(tree.sym); @@ -1282,7 +1285,10 @@ @Override public void visitNewClass(JCNewClass tree) { - if (lambdaNewClassFilter(context(), tree)) { + TypeSymbol def = tree.type.tsym; + boolean inReferencedClass = currentlyInClass(def); + boolean isLocal = def.isLocal(); + if ((inReferencedClass && isLocal || lambdaNewClassFilter(context(), tree))) { TranslationContext<?> localContext = context(); while (localContext != null) { if (localContext.tree.getTag() == LAMBDA) { @@ -1292,16 +1298,16 @@ localContext = localContext.prev; } } - if (context() != null && tree.type.tsym.owner.kind == MTH) { + if (context() != null && !inReferencedClass && isLocal) { LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context(); - captureLocalClassDefs(tree.type.tsym, lambdaContext); + captureLocalClassDefs(def, lambdaContext); } super.visitNewClass(tree); } //where void captureLocalClassDefs(Symbol csym, final LambdaTranslationContext lambdaContext) { JCClassDecl localCDef = localClassDefs.get(csym); - if (localCDef != null && localCDef.pos < lambdaContext.tree.pos) { + if (localCDef != null && lambdaContext.freeVarProcessedLocalClasses.add(csym)) { BasicFreeVarCollector fvc = lower.new BasicFreeVarCollector() { @Override void addFreeVars(ClassSymbol c) { @@ -1327,6 +1333,18 @@ fvc.scan(localCDef); } } + //where + boolean currentlyInClass(Symbol csym) { + for (Frame frame : frameStack) { + if (frame.tree.hasTag(JCTree.Tag.CLASSDEF)) { + JCClassDecl cdef = (JCClassDecl) frame.tree; + if (cdef.sym == csym) { + return true; + } + } + } + return false; + } /** * Method references to local class constructors, may, if the local @@ -1694,6 +1712,9 @@ /** does this functional expression require serialization support? */ boolean isSerializable() { + if (forceSerializable) { + return true; + } for (Type target : tree.targets) { if (types.asSuper(target, syms.serializableType.tsym) != null) { return true; @@ -1749,6 +1770,11 @@ List<JCVariableDecl> syntheticParams; + /** + * to prevent recursion, track local classes processed + */ + final Set<Symbol> freeVarProcessedLocalClasses; + LambdaTranslationContext(JCLambda tree) { super(tree); Frame frame = frameStack.head; @@ -1778,6 +1804,8 @@ translatedSymbols.put(CAPTURED_VAR, new LinkedHashMap<Symbol, Symbol>()); translatedSymbols.put(CAPTURED_THIS, new LinkedHashMap<Symbol, Symbol>()); translatedSymbols.put(TYPE_VAR, new LinkedHashMap<Symbol, Symbol>()); + + freeVarProcessedLocalClasses = new HashSet<>(); } /** @@ -1888,11 +1916,11 @@ }; break; case LOCAL_VAR: - ret = new VarSymbol(FINAL, name, types.erasure(sym.type), translatedSym); + ret = new VarSymbol(sym.flags() & FINAL, name, sym.type, translatedSym); ((VarSymbol) ret).pos = ((VarSymbol) sym).pos; break; case PARAM: - ret = new VarSymbol(FINAL | PARAMETER, name, types.erasure(sym.type), translatedSym); + ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, name, types.erasure(sym.type), translatedSym); ((VarSymbol) ret).pos = ((VarSymbol) sym).pos; break; default:
--- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2360,6 +2360,7 @@ /** Visitor method: Translate a single node. * Attach the source position from the old tree to its replacement tree. */ + @Override public <T extends JCTree> T translate(T tree) { if (tree == null) { return null;
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -92,11 +92,10 @@ TreeInfo treeinfo; Types types; JCDiagnostic.Factory diags; - public final boolean boxingEnabled; // = source.allowBoxing(); - public final boolean varargsEnabled; // = source.allowVarargs(); + public final boolean boxingEnabled; + public final boolean varargsEnabled; public final boolean allowMethodHandles; - public final boolean allowDefaultMethods; - public final boolean allowStructuralMostSpecific; + public final boolean allowFunctionalInterfaceMostSpecific; private final boolean debugResolve; private final boolean compactMethodDiags; final EnumSet<VerboseResolutionMode> verboseResolutionMode; @@ -137,8 +136,7 @@ verboseResolutionMode = VerboseResolutionMode.getVerboseResolutionMode(options); Target target = Target.instance(context); allowMethodHandles = target.hasMethodHandles(); - allowDefaultMethods = source.allowDefaultMethods(); - allowStructuralMostSpecific = source.allowStructuralMostSpecific(); + allowFunctionalInterfaceMostSpecific = source.allowFunctionalInterfaceMostSpecific(); polymorphicSignatureScope = new Scope(syms.noSymbol); inapplicableMethodException = new InapplicableMethodException(diags); @@ -567,7 +565,7 @@ tvars, (MethodType)mt, resultInfo, - m, + (MethodSymbol)m, argtypes, allowBoxing, useVarargs, @@ -775,6 +773,7 @@ public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { return nilMethodCheck; } + } /** @@ -786,6 +785,11 @@ void checkArg(DiagnosticPosition pos, boolean varargs, Type actual, Type formal, DeferredAttrContext deferredAttrContext, Warner warn) { //do nothing - actual always compatible to formals } + + @Override + public String toString() { + return "arityMethodCheck"; + } }; List<Type> dummyArgs(int length) { @@ -871,6 +875,11 @@ public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { return new MostSpecificCheck(strict, actuals); } + + @Override + public String toString() { + return "resolveMethodCheck"; + } }; /** @@ -901,8 +910,10 @@ @Override public boolean compatible(Type found, Type req, Warner warn) { - found = pendingInferenceContext.asFree(found); - req = infer.returnConstraintTarget(found, req); + found = pendingInferenceContext.asUndetVar(found); + if (found.hasTag(UNDETVAR) && req.isPrimitive()) { + req = types.boxedClass(req).type; + } return super.compatible(found, req, warn); } @@ -938,8 +949,8 @@ public boolean compatible(Type found, Type req, Warner warn) { return strict ? - types.isSubtypeUnchecked(found, deferredAttrContext.inferenceContext.asFree(req), warn) : - types.isConvertible(found, deferredAttrContext.inferenceContext.asFree(req), warn); + types.isSubtypeUnchecked(found, deferredAttrContext.inferenceContext.asUndetVar(req), warn) : + types.isConvertible(found, deferredAttrContext.inferenceContext.asUndetVar(req), warn); } public void report(DiagnosticPosition pos, JCDiagnostic details) { @@ -957,6 +968,12 @@ public DeferredAttrContext deferredAttrContext() { return deferredAttrContext; } + + @Override + public String toString() { + return "MethodReferenceCheck"; + } + } /** @@ -975,7 +992,12 @@ DeferredType dt = (DeferredType)found; return dt.check(this); } else { - return super.check(pos, chk.checkNonVoid(pos, types.capture(U(found.baseType())))); + Type uResult = U(found.baseType()); + Type capturedType = pos == null || pos.getTree() == null ? + types.capture(uResult) : + checkContext.inferenceContext() + .cachedCapture(pos.getTree(), uResult, true); + return super.check(pos, chk.checkNonVoid(pos, capturedType)); } } @@ -1059,50 +1081,47 @@ } public boolean compatible(Type found, Type req, Warner warn) { - if (!allowStructuralMostSpecific || actual == null) { - return super.compatible(found, req, warn); - } else { - switch (actual.getTag()) { - case DEFERRED: - DeferredType dt = (DeferredType) actual; - DeferredType.SpeculativeCache.Entry e = dt.speculativeCache.get(deferredAttrContext.msym, deferredAttrContext.phase); - return (e == null || e.speculativeTree == deferredAttr.stuckTree) - ? super.compatible(found, req, warn) : - mostSpecific(found, req, e.speculativeTree, warn); - default: - return standaloneMostSpecific(found, req, actual, warn); + if (allowFunctionalInterfaceMostSpecific && + unrelatedFunctionalInterfaces(found, req) && + (actual != null && actual.getTag() == DEFERRED)) { + DeferredType dt = (DeferredType) actual; + DeferredType.SpeculativeCache.Entry e = + dt.speculativeCache.get(deferredAttrContext.msym, deferredAttrContext.phase); + if (e != null && e.speculativeTree != deferredAttr.stuckTree) { + return functionalInterfaceMostSpecific(found, req, e.speculativeTree, warn); } } + return super.compatible(found, req, warn); } - private boolean mostSpecific(Type t, Type s, JCTree tree, Warner warn) { - MostSpecificChecker msc = new MostSpecificChecker(t, s, warn); + /** Whether {@code t} and {@code s} are unrelated functional interface types. */ + private boolean unrelatedFunctionalInterfaces(Type t, Type s) { + return types.isFunctionalInterface(t.tsym) && + types.isFunctionalInterface(s.tsym) && + types.asSuper(t, s.tsym) == null && + types.asSuper(s, t.tsym) == null; + } + + /** Parameters {@code t} and {@code s} are unrelated functional interface types. */ + private boolean functionalInterfaceMostSpecific(Type t, Type s, JCTree tree, Warner warn) { + FunctionalInterfaceMostSpecificChecker msc = new FunctionalInterfaceMostSpecificChecker(t, s, warn); msc.scan(tree); return msc.result; } - boolean polyMostSpecific(Type t1, Type t2, Warner warn) { - return (!t1.isPrimitive() && t2.isPrimitive()) - ? true : super.compatible(t1, t2, warn); - } - - boolean standaloneMostSpecific(Type t1, Type t2, Type exprType, Warner warn) { - return (exprType.isPrimitive() == t1.isPrimitive() - && exprType.isPrimitive() != t2.isPrimitive()) - ? true : super.compatible(t1, t2, warn); - } - /** - * Structural checker for most specific. + * Tests whether one functional interface type can be considered more specific + * than another unrelated functional interface type for the scanned expression. */ - class MostSpecificChecker extends DeferredAttr.PolyScanner { + class FunctionalInterfaceMostSpecificChecker extends DeferredAttr.PolyScanner { final Type t; final Type s; final Warner warn; boolean result; - MostSpecificChecker(Type t, Type s, Warner warn) { + /** Parameters {@code t} and {@code s} are unrelated functional interface types. */ + FunctionalInterfaceMostSpecificChecker(Type t, Type s, Warner warn) { this.t = t; this.s = s; this.warn = warn; @@ -1111,102 +1130,96 @@ @Override void skip(JCTree tree) { - result &= standaloneMostSpecific(t, s, tree.type, warn); + result &= false; } @Override public void visitConditional(JCConditional tree) { - if (tree.polyKind == PolyKind.STANDALONE) { - result &= standaloneMostSpecific(t, s, tree.type, warn); - } else { - super.visitConditional(tree); - } - } - - @Override - public void visitApply(JCMethodInvocation tree) { - result &= (tree.polyKind == PolyKind.STANDALONE) - ? standaloneMostSpecific(t, s, tree.type, warn) - : polyMostSpecific(t, s, warn); - } - - @Override - public void visitNewClass(JCNewClass tree) { - result &= (tree.polyKind == PolyKind.STANDALONE) - ? standaloneMostSpecific(t, s, tree.type, warn) - : polyMostSpecific(t, s, warn); + scan(tree.truepart); + scan(tree.falsepart); } @Override public void visitReference(JCMemberReference tree) { - if (types.isFunctionalInterface(t.tsym) && - types.isFunctionalInterface(s.tsym)) { - Type desc_t = types.findDescriptorType(t); - Type desc_s = types.findDescriptorType(s); - if (types.isSameTypes(desc_t.getParameterTypes(), - inferenceContext().asFree(desc_s.getParameterTypes()))) { - if (types.asSuper(t, s.tsym) != null || - types.asSuper(s, t.tsym) != null) { - result &= MostSpecificCheckContext.super.compatible(t, s, warn); - } else if (!desc_s.getReturnType().hasTag(VOID)) { - //perform structural comparison - Type ret_t = desc_t.getReturnType(); - Type ret_s = desc_s.getReturnType(); - result &= ((tree.refPolyKind == PolyKind.STANDALONE) - ? standaloneMostSpecific(ret_t, ret_s, tree.sym.type.getReturnType(), warn) - : polyMostSpecific(ret_t, ret_s, warn)); - } else { - return; - } + Type desc_t = types.findDescriptorType(t); + Type desc_s = types.findDescriptorType(s); + // use inference variables here for more-specific inference (18.5.4) + if (!types.isSameTypes(desc_t.getParameterTypes(), + inferenceContext().asUndetVars(desc_s.getParameterTypes()))) { + result &= false; + } else { + // compare return types + Type ret_t = desc_t.getReturnType(); + Type ret_s = desc_s.getReturnType(); + if (ret_s.hasTag(VOID)) { + result &= true; + } else if (ret_t.hasTag(VOID)) { + result &= false; + } else if (ret_t.isPrimitive() != ret_s.isPrimitive()) { + boolean retValIsPrimitive = + tree.refPolyKind == PolyKind.STANDALONE && + tree.sym.type.getReturnType().isPrimitive(); + result &= (retValIsPrimitive == ret_t.isPrimitive()) && + (retValIsPrimitive != ret_s.isPrimitive()); + } else { + result &= MostSpecificCheckContext.super.compatible(ret_t, ret_s, warn); } - } else { - result &= false; } } @Override public void visitLambda(JCLambda tree) { - if (types.isFunctionalInterface(t.tsym) && - types.isFunctionalInterface(s.tsym)) { - Type desc_t = types.findDescriptorType(t); - Type desc_s = types.findDescriptorType(s); - if (types.isSameTypes(desc_t.getParameterTypes(), - inferenceContext().asFree(desc_s.getParameterTypes()))) { - if (types.asSuper(t, s.tsym) != null || - types.asSuper(s, t.tsym) != null) { - result &= MostSpecificCheckContext.super.compatible(t, s, warn); - } else if (!desc_s.getReturnType().hasTag(VOID)) { - //perform structural comparison - Type ret_t = desc_t.getReturnType(); - Type ret_s = desc_s.getReturnType(); - scanLambdaBody(tree, ret_t, ret_s); - } else { - return; + Type desc_t = types.findDescriptorType(t); + Type desc_s = types.findDescriptorType(s); + // use inference variables here for more-specific inference (18.5.4) + if (!types.isSameTypes(desc_t.getParameterTypes(), + inferenceContext().asUndetVars(desc_s.getParameterTypes()))) { + result &= false; + } else { + // compare return types + Type ret_t = desc_t.getReturnType(); + Type ret_s = desc_s.getReturnType(); + if (ret_s.hasTag(VOID)) { + result &= true; + } else if (ret_t.hasTag(VOID)) { + result &= false; + } else if (unrelatedFunctionalInterfaces(ret_t, ret_s)) { + for (JCExpression expr : lambdaResults(tree)) { + result &= functionalInterfaceMostSpecific(ret_t, ret_s, expr, warn); } + } else if (ret_t.isPrimitive() != ret_s.isPrimitive()) { + for (JCExpression expr : lambdaResults(tree)) { + boolean retValIsPrimitive = expr.isStandalone() && expr.type.isPrimitive(); + result &= (retValIsPrimitive == ret_t.isPrimitive()) && + (retValIsPrimitive != ret_s.isPrimitive()); + } + } else { + result &= MostSpecificCheckContext.super.compatible(ret_t, ret_s, warn); } - } else { - result &= false; } } //where - void scanLambdaBody(JCLambda lambda, final Type t, final Type s) { + private List<JCExpression> lambdaResults(JCLambda lambda) { if (lambda.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) { - result &= MostSpecificCheckContext.this.mostSpecific(t, s, lambda.body, warn); + return List.of((JCExpression) lambda.body); } else { + final ListBuffer<JCExpression> buffer = new ListBuffer<>(); DeferredAttr.LambdaReturnScanner lambdaScanner = new DeferredAttr.LambdaReturnScanner() { @Override public void visitReturn(JCReturn tree) { if (tree.expr != null) { - result &= MostSpecificCheckContext.this.mostSpecific(t, s, tree.expr, warn); + buffer.append(tree.expr); } } }; lambdaScanner.scan(lambda.body); + return buffer.toList(); } } } + } public MethodCheck mostSpecificCheck(List<Type> actuals, boolean strict) { @@ -1410,7 +1423,7 @@ return bestSoFar; } else if (useVarargs && (sym.flags() & VARARGS) == 0) { return bestSoFar.kind >= ERRONEOUS ? - new BadVarargsMethod((ResolveError)bestSoFar) : + new BadVarargsMethod((ResolveError)bestSoFar.baseSymbol()) : bestSoFar; } Assert.check(sym.kind < AMBIGUOUS); @@ -1502,14 +1515,22 @@ if (m2SignatureMoreSpecific) return m2; return ambiguityError(m1, m2); case AMBIGUOUS: - //check if m1 is more specific than all ambiguous methods in m2 + //compare m1 to ambiguous methods in m2 AmbiguityError e = (AmbiguityError)m2.baseSymbol(); + boolean m1MoreSpecificThanAnyAmbiguous = true; + boolean allAmbiguousMoreSpecificThanM1 = true; for (Symbol s : e.ambiguousSyms) { - if (mostSpecific(argtypes, m1, s, env, site, allowBoxing, useVarargs) != m1) { - return e.addAmbiguousSymbol(m1); - } + Symbol moreSpecific = mostSpecific(argtypes, m1, s, env, site, allowBoxing, useVarargs); + m1MoreSpecificThanAnyAmbiguous &= moreSpecific == m1; + allAmbiguousMoreSpecificThanM1 &= moreSpecific == s; } - return m1; + if (m1MoreSpecificThanAnyAmbiguous) + return m1; + //if m1 is more specific than some ambiguous methods, but other ambiguous methods are + //more specific than m1, add it as a new ambiguous method: + if (!allAmbiguousMoreSpecificThanM1) + e.addAmbiguousSymbol(m1); + return e; default: throw new AssertionError(); } @@ -1527,7 +1548,7 @@ currentResolutionContext.methodCheck = prevResolutionContext.methodCheck.mostSpecificCheck(actuals, !allowBoxing); Type mst = instantiate(env, site, m2, null, - adjustArgs(types.lowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null, + adjustArgs(types.cvarLowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null, allowBoxing, useVarargs, noteWarner); return mst != null && !noteWarner.hasLint(Lint.LintCategory.UNCHECKED); @@ -1681,7 +1702,6 @@ bestSoFar : methodNotFound; for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) { - if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && !allowDefaultMethods) break; //keep searching for abstract methods for (Type itype : itypes[iphase2.ordinal()]) { if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure()) @@ -1714,10 +1734,8 @@ //from superinterfaces) if ((s.flags() & (ABSTRACT | INTERFACE | ENUM)) != 0) { return this; - } else if (rs.allowDefaultMethods) { + } else { return DEFAULT_OK; - } else { - return null; } } }, @@ -2173,7 +2191,7 @@ List<Type> typeargtypes, LogResolveHelper logResolveHelper) { if (sym.kind >= AMBIGUOUS) { - ResolveError errSym = (ResolveError)sym; + ResolveError errSym = (ResolveError)sym.baseSymbol(); sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol); argtypes = logResolveHelper.getArgumentTypes(errSym, sym, name, argtypes); if (logResolveHelper.resolveDiagnosticNeeded(site, argtypes, typeargtypes)) { @@ -2562,7 +2580,7 @@ sym = super.access(env, pos, location, sym); } else { final JCDiagnostic details = sym.kind == WRONG_MTH ? - ((InapplicableSymbolError)sym).errCandidate().snd : + ((InapplicableSymbolError)sym.baseSymbol()).errCandidate().snd : null; sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) { @Override @@ -2970,12 +2988,12 @@ return true; case WRONG_MTH: InapplicableSymbolError errSym = - (InapplicableSymbolError)s; + (InapplicableSymbolError)s.baseSymbol(); return new Template(MethodCheckDiag.ARITY_MISMATCH.regex()) .matches(errSym.errCandidate().snd); case WRONG_MTHS: InapplicableSymbolsError errSyms = - (InapplicableSymbolsError)s; + (InapplicableSymbolsError)s.baseSymbol(); return errSyms.filterCandidates(errSyms.mapCandidates()).isEmpty(); case WRONG_STATICNESS: return false; @@ -3157,7 +3175,7 @@ if (TreeInfo.isStaticSelector(referenceTree.expr, names) && argtypes.nonEmpty() && (argtypes.head.hasTag(NONE) || - types.isSubtypeUnchecked(inferenceContext.asFree(argtypes.head), site))) { + types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head), site))) { return new UnboundMethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase); } else { @@ -3341,9 +3359,9 @@ if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; env1 = env1.outer; } - if (allowDefaultMethods && c.isInterface() && - name == names._super && !isStatic(env) && - types.isDirectSuperInterface(c, env.enclClass.sym)) { + if (c.isInterface() && + name == names._super && !isStatic(env) && + types.isDirectSuperInterface(c, env.enclClass.sym)) { //this might be a default super call if one of the superinterfaces is 'c' for (Type t : pruneInterfaces(env.enclClass.type)) { if (t.tsym == c) { @@ -4270,7 +4288,11 @@ } DeferredAttrContext deferredAttrContext(Symbol sym, InferenceContext inferenceContext, ResultInfo pendingResult, Warner warn) { - return deferredAttr.new DeferredAttrContext(attrMode, sym, step, inferenceContext, pendingResult != null ? pendingResult.checkContext.deferredAttrContext() : deferredAttr.emptyDeferredAttrContext, warn); + DeferredAttrContext parent = (pendingResult == null) + ? deferredAttr.emptyDeferredAttrContext + : pendingResult.checkContext.deferredAttrContext(); + return deferredAttr.new DeferredAttrContext(attrMode, sym, step, + inferenceContext, parent, warn); } /**
--- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -835,6 +835,8 @@ public void visitReference(JCMemberReference tree) { tree.expr = translate(tree.expr, erasure(tree.expr.type)); tree.type = erasure(tree.type); + if (tree.varargsElement != null) + tree.varargsElement = erasure(tree.varargsElement); result = tree; }
--- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -116,10 +116,6 @@ */ boolean lintClassfile; - /** Switch: allow default methods - */ - boolean allowDefaultMethods; - /** Switch: preserve parameter names from the variable table. */ public boolean saveParameterNames; @@ -307,7 +303,6 @@ allowVarargs = source.allowVarargs(); allowAnnotations = source.allowAnnotations(); allowSimplifiedVarargs = source.allowSimplifiedVarargs(); - allowDefaultMethods = source.allowDefaultMethods(); saveParameterNames = options.isSet("save-parameter-names"); cacheCompletionFailure = options.isUnset("dev"); @@ -517,14 +512,14 @@ break; case CONSTANT_Fieldref: { ClassSymbol owner = readClassSymbol(getChar(index + 1)); - NameAndType nt = (NameAndType)readPool(getChar(index + 3)); + NameAndType nt = readNameAndType(getChar(index + 3)); poolObj[i] = new VarSymbol(0, nt.name, nt.uniqueType.type, owner); break; } case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: { ClassSymbol owner = readClassSymbol(getChar(index + 1)); - NameAndType nt = (NameAndType)readPool(getChar(index + 3)); + NameAndType nt = readNameAndType(getChar(index + 3)); poolObj[i] = new MethodSymbol(0, nt.name, nt.uniqueType.type, owner); break; } @@ -593,13 +588,34 @@ /** Read class entry. */ ClassSymbol readClassSymbol(int i) { - return (ClassSymbol) (readPool(i)); + Object obj = readPool(i); + if (obj != null && !(obj instanceof ClassSymbol)) + throw badClassFile("bad.const.pool.entry", + currentClassFile.toString(), + "CONSTANT_Class_info", i); + return (ClassSymbol)obj; } /** Read name. */ Name readName(int i) { - return (Name) (readPool(i)); + Object obj = readPool(i); + if (obj != null && !(obj instanceof Name)) + throw badClassFile("bad.const.pool.entry", + currentClassFile.toString(), + "CONSTANT_Utf8_info or CONSTANT_String_info", i); + return (Name)obj; + } + + /** Read name and type. + */ + NameAndType readNameAndType(int i) { + Object obj = readPool(i); + if (obj != null && !(obj instanceof NameAndType)) + throw badClassFile("bad.const.pool.entry", + currentClassFile.toString(), + "CONSTANT_NameAndType_info", i); + return (NameAndType)obj; } /************************************************************************ @@ -1250,7 +1266,7 @@ sym.owner.members().remove(sym); ClassSymbol self = (ClassSymbol)sym; ClassSymbol c = readClassSymbol(nextChar()); - NameAndType nt = (NameAndType)readPool(nextChar()); + NameAndType nt = readNameAndType(nextChar()); if (c.members_field == null) throw badClassFile("bad.enclosing.class", self, c);
--- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Thu May 29 13:46:36 2014 -0700 @@ -1038,7 +1038,7 @@ } databuf.appendChar(pool.get(inner)); databuf.appendChar( - inner.owner.kind == TYP ? pool.get(inner.owner) : 0); + inner.owner.kind == TYP && !inner.name.isEmpty() ? pool.get(inner.owner) : 0); databuf.appendChar( !inner.name.isEmpty() ? pool.get(inner.name) : 0); databuf.appendChar(flags);
--- a/src/share/classes/com/sun/tools/javac/jvm/Code.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2189,9 +2189,9 @@ // Keep local variables if // 1) we need them for debug information // 2) it is an exception type and it contains type annotations - if (!varDebugInfo && - (!var.sym.isExceptionParameter() || - var.sym.hasTypeAnnotations())) return; + boolean keepLocalVariables = varDebugInfo || + (var.sym.isExceptionParameter() && var.sym.hasTypeAnnotations()); + if (!keepLocalVariables) return; if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return; if (varBuffer == null) varBuffer = new LocalVar[20];
--- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -2818,7 +2818,7 @@ } private LVTAssignAnalyzer(LVTRanges lvtRanges, Symtab syms, Names names) { - super(new LVTBits(), syms, names); + super(new LVTBits(), syms, names, false); lvtInits = (LVTBits)inits; this.lvtRanges = lvtRanges; }
--- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Thu May 29 13:46:36 2014 -0700 @@ -35,9 +35,6 @@ import java.util.Queue; import java.util.ResourceBundle; import java.util.Set; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.annotation.processing.Processor; import javax.lang.model.SourceVersion; @@ -1304,11 +1301,16 @@ * Perform dataflow checks on an attributed parse tree. */ protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results) { + if (compileStates.isDone(env, CompileState.FLOW)) { + results.add(env); + return; + } + try { if (shouldStop(CompileState.FLOW)) return; - if (relax || compileStates.isDone(env, CompileState.FLOW)) { + if (relax) { results.add(env); return; }
--- a/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1172,8 +1172,10 @@ DCText string = quotedString(); if (string != null) { skipWhitespace(); - if (ch == '@') + if (ch == '@' + || ch == EOI && bp == buf.length - 1) { return m.at(pos).See(List.<DCTree>of(string)); + } } break;
--- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu May 29 13:46:36 2014 -0700 @@ -161,6 +161,7 @@ this.allowStaticInterfaceMethods = source.allowStaticInterfaceMethods(); this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast(); this.allowTypeAnnotations = source.allowTypeAnnotations(); + this.allowAnnotationsAfterTypeParams = source.allowAnnotationsAfterTypeParams(); this.keepDocComments = keepDocComments; docComments = newDocCommentTable(keepDocComments, fac); this.keepLineMap = keepLineMap; @@ -254,6 +255,10 @@ */ boolean allowTypeAnnotations; + /** Switch: should we allow annotations after the method type parameters? + */ + boolean allowAnnotationsAfterTypeParams; + /** Switch: is "this" allowed as an identifier? * This is needed to parse receiver types. */ @@ -2020,7 +2025,7 @@ /** Creator = [Annotations] Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest ) */ JCExpression creator(int newpos, List<JCExpression> typeArgs) { - List<JCAnnotation> newAnnotations = annotationsOpt(Tag.ANNOTATION); + List<JCAnnotation> newAnnotations = typeAnnotationsOpt(); switch (token.kind) { case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT: @@ -3401,16 +3406,28 @@ * | ModifiersOpt * ( Type Ident * ( VariableDeclaratorsRest ";" | MethodDeclaratorRest ) - * | VOID Ident MethodDeclaratorRest - * | TypeParameters (Type | VOID) Ident MethodDeclaratorRest + * | VOID Ident VoidMethodDeclaratorRest + * | TypeParameters [Annotations] + * ( Type Ident MethodDeclaratorRest + * | VOID Ident VoidMethodDeclaratorRest + * ) * | Ident ConstructorDeclaratorRest * | TypeParameters Ident ConstructorDeclaratorRest * | ClassOrInterfaceOrEnumDeclaration * ) * InterfaceBodyDeclaration = * ";" - * | ModifiersOpt Type Ident - * ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" ) + * | ModifiersOpt + * ( Type Ident + * ( ConstantDeclaratorsRest ";" | MethodDeclaratorRest ) + * | VOID Ident MethodDeclaratorRest + * | TypeParameters [Annotations] + * ( Type Ident MethodDeclaratorRest + * | VOID Ident VoidMethodDeclaratorRest + * ) + * | ClassOrInterfaceOrEnumDeclaration + * ) + * */ protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { if (token.kind == SEMI) { @@ -3439,27 +3456,29 @@ } List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION); + if (annosAfterParams.nonEmpty()) { + checkAnnotationsAfterTypeParams(annosAfterParams.head.pos); + mods.annotations = mods.annotations.appendList(annosAfterParams); + if (mods.pos == Position.NOPOS) + mods.pos = mods.annotations.head.pos; + } + Token tk = token; pos = token.pos; JCExpression type; boolean isVoid = token.kind == VOID; if (isVoid) { - if (annosAfterParams.nonEmpty()) - illegal(annosAfterParams.head.pos); type = to(F.at(pos).TypeIdent(TypeTag.VOID)); nextToken(); } else { - if (annosAfterParams.nonEmpty()) { - mods.annotations = mods.annotations.appendList(annosAfterParams); - if (mods.pos == Position.NOPOS) - mods.pos = mods.annotations.head.pos; - } // method returns types are un-annotated types type = unannotatedType(); } if (token.kind == LPAREN && !isInterface && type.hasTag(IDENT)) { if (isInterface || tk.name() != className) error(pos, "invalid.meth.decl.ret.type.req"); + else if (annosAfterParams.nonEmpty()) + illegal(annosAfterParams.head.pos); return List.of(methodDeclaratorRest( pos, mods, null, names.init, typarams, isInterface, true, dc)); @@ -3491,13 +3510,9 @@ } /** MethodDeclaratorRest = - * FormalParameters BracketsOpt [Throws TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";") + * FormalParameters BracketsOpt [THROWS TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";") * VoidMethodDeclaratorRest = - * FormalParameters [Throws TypeList] ( MethodBody | ";") - * InterfaceMethodDeclaratorRest = - * FormalParameters BracketsOpt [THROWS TypeList] ";" - * VoidInterfaceMethodDeclaratorRest = - * FormalParameters [THROWS TypeList] ";" + * FormalParameters [THROWS TypeList] ( MethodBody | ";") * ConstructorDeclaratorRest = * "(" FormalParameterListOpt ")" [THROWS TypeList] MethodBody */ @@ -4041,6 +4056,12 @@ allowTypeAnnotations = true; } } + void checkAnnotationsAfterTypeParams(int pos) { + if (!allowAnnotationsAfterTypeParams) { + log.error(pos, "annotations.after.type.params.not.supported.in.source", source.name); + allowAnnotationsAfterTypeParams = true; + } + } /* * a functional source tree and end position mappings
--- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu May 29 13:46:36 2014 -0700 @@ -762,14 +762,14 @@ public Set<TypeElement> visitType(TypeElement e, Set<TypeElement> p) { // Type parameters are not considered to be enclosed by a type scan(e.getTypeParameters(), p); - return scan(e.getEnclosedElements(), p); + return super.visitType(e, p); } @Override public Set<TypeElement> visitExecutable(ExecutableElement e, Set<TypeElement> p) { // Type parameters are not considered to be enclosed by an executable scan(e.getTypeParameters(), p); - return scan(e.getEnclosedElements(), p); + return super.visitExecutable(e, p); } void addAnnotations(Element e, Set<TypeElement> p) {
--- a/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacRoundEnvironment.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,11 +26,8 @@ package com.sun.tools.javac.processing; import java.lang.annotation.Annotation; -import com.sun.tools.javac.tree.JCTree.*; import javax.annotation.processing.*; import javax.lang.model.element.*; -import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeMirror; import javax.lang.model.util.*; import java.util.*; @@ -114,58 +111,48 @@ */ public Set<? extends Element> getElementsAnnotatedWith(TypeElement a) { Set<Element> result = Collections.emptySet(); - Types typeUtil = processingEnv.getTypeUtils(); if (a.getKind() != ElementKind.ANNOTATION_TYPE) throw new IllegalArgumentException(NOT_AN_ANNOTATION_TYPE + a); - DeclaredType annotationTypeElement; - TypeMirror tm = a.asType(); - if ( tm instanceof DeclaredType ) - annotationTypeElement = (DeclaredType) a.asType(); - else - throw new AssertionError("Bad implementation type for " + tm); - - ElementScanner8<Set<Element>, DeclaredType> scanner = - new AnnotationSetScanner(result, typeUtil); + ElementScanner8<Set<Element>, TypeElement> scanner = + new AnnotationSetScanner(result); for (Element element : rootElements) - result = scanner.scan(element, annotationTypeElement); + result = scanner.scan(element, a); return result; } // Could be written as a local class inside getElementsAnnotatedWith private class AnnotationSetScanner extends - ElementScanner8<Set<Element>, DeclaredType> { + ElementScanner8<Set<Element>, TypeElement> { // Insertion-order preserving set Set<Element> annotatedElements = new LinkedHashSet<Element>(); - Types typeUtil; - AnnotationSetScanner(Set<Element> defaultSet, Types typeUtil) { + AnnotationSetScanner(Set<Element> defaultSet) { super(defaultSet); - this.typeUtil = typeUtil; } @Override - public Set<Element> visitType(TypeElement e, DeclaredType p) { + public Set<Element> visitType(TypeElement e, TypeElement p) { // Type parameters are not considered to be enclosed by a type scan(e.getTypeParameters(), p); - return scan(e.getEnclosedElements(), p); + return super.visitType(e, p); } @Override - public Set<Element> visitExecutable(ExecutableElement e, DeclaredType p) { + public Set<Element> visitExecutable(ExecutableElement e, TypeElement p) { // Type parameters are not considered to be enclosed by an executable scan(e.getTypeParameters(), p); - return scan(e.getEnclosedElements(), p); + return super.visitExecutable(e, p); } @Override - public Set<Element> scan(Element e, DeclaredType p) { + public Set<Element> scan(Element e, TypeElement p) { java.util.List<? extends AnnotationMirror> annotationMirrors = processingEnv.getElementUtils().getAllAnnotationMirrors(e); for (AnnotationMirror annotationMirror : annotationMirrors) { - if (typeUtil.isSameType(annotationMirror.getAnnotationType(), p)) + if (p.equals(annotationMirror.getAnnotationType().asElement())) annotatedElements.add(e); } e.accept(this, p);
--- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -123,6 +123,9 @@ compiler.err.anon.class.impl.intf.no.qual.for.new=\ anonymous class implements interface; cannot have qualifier for new +compiler.err.cant.inherit.from.anon=\ + cannot inherit from anonymous class + # 0: symbol, 1: symbol, 2: symbol compiler.err.array.and.varargs=\ cannot declare both {0} and {1} in {2} @@ -732,6 +735,9 @@ bad return type in method reference\n\ {0} +compiler.err.lambda.body.neither.value.nor.void.compatible=\ + lambda body is neither value nor void compatible + # 0: list of type compiler.err.incompatible.thrown.types.in.mref=\ incompatible thrown types {0} in method reference @@ -1611,6 +1617,10 @@ compiler.warn.varargs.redundant.trustme.anno=\ Redundant {0} annotation. {1} +# 0: symbol +compiler.warn.access.to.sensitive.member.from.serializable.element=\ + access to sensitive member {0} from serializable element can be publicly accessible to untrusted code + ##### ## The following are tokens which are non-terminals in the language. They should @@ -1699,6 +1709,11 @@ cannot access {0}\n\ {1} +# 0: file name, 1: expected CP entry type, 2: constant pool index +compiler.misc.bad.const.pool.entry=\ + bad constant pool entry in {0}\n\ + expected {1} at index {2} + # 0: file name, 1: message segment compiler.misc.bad.class.file.header=\ bad class file: {0}\n\ @@ -2311,6 +2326,11 @@ (use -source 8 or higher to enable type annotations) # 0: string +compiler.err.annotations.after.type.params.not.supported.in.source=\ + annotations after method type parameters are not supported in -source {0}\n\ +(use -source 8 or higher to enable annotations after method type parameters) + +# 0: string compiler.err.repeatable.annotations.not.supported.in.source=\ repeated annotations are not supported in -source {0}\n\ (use -source 8 or higher to enable repeated annotations)
--- a/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -30,14 +30,14 @@ javac.opt.g.lines.vars.source=\u3044\u304F\u3064\u304B\u306E\u30C7\u30D0\u30C3\u30B0\u60C5\u5831\u306E\u307F\u3092\u751F\u6210\u3059\u308B javac.opt.nowarn=\u8B66\u544A\u3092\u767A\u751F\u3055\u305B\u306A\u3044 javac.opt.verbose=\u30B3\u30F3\u30D1\u30A4\u30E9\u306E\u52D5\u4F5C\u306B\u3064\u3044\u3066\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u51FA\u529B\u3059\u308B -javac.opt.deprecation=\u975E\u63A8\u5968\u306EAPI\u304C\u4F7F\u7528\u3055\u308C\u3066\u3044\u308B\u30BD\u30FC\u30B9\u306E\u4F4D\u7F6E\u3092\u51FA\u529B\u3059\u308B +javac.opt.deprecation=\u975E\u63A8\u5968\u306EAPI\u304C\u4F7F\u7528\u3055\u308C\u3066\u3044\u308B\u30BD\u30FC\u30B9\u306E\u5834\u6240\u3092\u51FA\u529B\u3059\u308B javac.opt.classpath=\u30E6\u30FC\u30B6\u30FC\u30FB\u30AF\u30E9\u30B9\u30FB\u30D5\u30A1\u30A4\u30EB\u304A\u3088\u3073\u6CE8\u91C8\u30D7\u30ED\u30BB\u30C3\u30B5\u3092\u691C\u7D22\u3059\u308B\u4F4D\u7F6E\u3092\u6307\u5B9A\u3059\u308B javac.opt.sourcepath=\u5165\u529B\u30BD\u30FC\u30B9\u30FB\u30D5\u30A1\u30A4\u30EB\u3092\u691C\u7D22\u3059\u308B\u4F4D\u7F6E\u3092\u6307\u5B9A\u3059\u308B -javac.opt.bootclasspath=\u30D6\u30FC\u30C8\u30B9\u30C8\u30E9\u30C3\u30D7\u30FB\u30AF\u30E9\u30B9\u30FB\u30D1\u30B9\u306E\u4F4D\u7F6E\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3059\u308B +javac.opt.bootclasspath=\u30D6\u30FC\u30C8\u30B9\u30C8\u30E9\u30C3\u30D7\u30FB\u30AF\u30E9\u30B9\u30FB\u30D1\u30B9\u306E\u5834\u6240\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3059\u308B javac.opt.Xbootclasspath.p=\u30D6\u30FC\u30C8\u30B9\u30C8\u30E9\u30C3\u30D7\u30FB\u30AF\u30E9\u30B9\u30FB\u30D1\u30B9\u306B\u4ED8\u52A0\u3059\u308B javac.opt.Xbootclasspath.a=\u30D6\u30FC\u30C8\u30B9\u30C8\u30E9\u30C3\u30D7\u30FB\u30AF\u30E9\u30B9\u30FB\u30D1\u30B9\u306B\u8FFD\u52A0\u3059\u308B -javac.opt.endorseddirs=\u63A8\u5968\u898F\u683C\u30D1\u30B9\u306E\u4F4D\u7F6E\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3059\u308B -javac.opt.extdirs=\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u6E08\u307F\u62E1\u5F35\u6A5F\u80FD\u306E\u4F4D\u7F6E\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3059\u308B +javac.opt.endorseddirs=\u63A8\u5968\u898F\u683C\u30D1\u30B9\u306E\u5834\u6240\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3059\u308B +javac.opt.extdirs=\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u6E08\u307F\u62E1\u5F35\u6A5F\u80FD\u306E\u5834\u6240\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3059\u308B javac.opt.processorpath=\u6CE8\u91C8\u30D7\u30ED\u30BB\u30C3\u30B5\u3092\u691C\u7D22\u3059\u308B\u4F4D\u7F6E\u3092\u6307\u5B9A\u3059\u308B javac.opt.processor=\u5B9F\u884C\u3059\u308B\u6CE8\u91C8\u30D7\u30ED\u30BB\u30C3\u30B5\u306E\u540D\u524D\u3002\u30C7\u30D5\u30A9\u30EB\u30C8\u306E\u691C\u51FA\u51E6\u7406\u3092\u30D0\u30A4\u30D1\u30B9 javac.opt.parameters=\u30E1\u30BD\u30C3\u30C9\u30FB\u30D1\u30E9\u30E1\u30FC\u30BF\u306B\u30EA\u30D5\u30EC\u30AF\u30B7\u30E7\u30F3\u7528\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u751F\u6210\u3057\u307E\u3059 @@ -133,7 +133,7 @@ javac.msg.usage.nonstandard.footer=\u3053\u308C\u3089\u306F\u975E\u6A19\u6E96\u30AA\u30D7\u30B7\u30E7\u30F3\u3067\u3042\u308A\u4E88\u544A\u306A\u3057\u306B\u5909\u66F4\u3055\u308C\u308B\u3053\u3068\u304C\u3042\u308A\u307E\u3059\u3002 -javac.msg.bug=\u30B3\u30F3\u30D1\u30A4\u30E9\u3067\u4F8B\u5916\u304C\u767A\u751F\u3057\u307E\u3057\u305F({0})\u3002Bug Parade\u306B\u540C\u3058\u30D0\u30B0\u304C\u767B\u9332\u3055\u308C\u3066\u3044\u306A\u3044\u3053\u3068\u3092\u3054\u78BA\u8A8D\u306E\u4E0A\u3001Java Developer Connection(http://java.sun.com/webapps/bugreport)\u3067\u30D0\u30B0\u306E\u767B\u9332\u3092\u304A\u9858\u3044\u3044\u305F\u3057\u307E\u3059\u3002\u30EC\u30DD\u30FC\u30C8\u306B\u306F\u3001\u305D\u306E\u30D7\u30ED\u30B0\u30E9\u30E0\u3068\u4E0B\u8A18\u306E\u8A3A\u65AD\u5185\u5BB9\u3092\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u3054\u5354\u529B\u3042\u308A\u304C\u3068\u3046\u3054\u3056\u3044\u307E\u3059\u3002 +javac.msg.bug=\u30B3\u30F3\u30D1\u30A4\u30E9\u3067\u4F8B\u5916\u304C\u767A\u751F\u3057\u307E\u3057\u305F({0})\u3002Bug Parade\u3067\u91CD\u8907\u304C\u306A\u3044\u304B\u3092\u3054\u78BA\u8A8D\u306E\u3046\u3048\u3001Java Developer Connection (http://java.sun.com/webapps/bugreport)\u3067bug\u306E\u767B\u9332\u3092\u304A\u9858\u3044\u3044\u305F\u3057\u307E\u3059\u3002\u30EC\u30DD\u30FC\u30C8\u306B\u306F\u3001\u305D\u306E\u30D7\u30ED\u30B0\u30E9\u30E0\u3068\u4E0B\u8A18\u306E\u8A3A\u65AD\u5185\u5BB9\u3092\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u3054\u5354\u529B\u3042\u308A\u304C\u3068\u3046\u3054\u3056\u3044\u307E\u3059\u3002 javac.msg.io=\n\n\u5165\u51FA\u529B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\n\u8A73\u7D30\u306F\u6B21\u306E\u30B9\u30BF\u30C3\u30AF\u30FB\u30C8\u30EC\u30FC\u30B9\u3067\u8ABF\u67FB\u3057\u3066\u304F\u3060\u3055\u3044\u3002\n
--- a/src/share/classes/com/sun/tools/javac/sym/Profiles.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/sym/Profiles.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -153,6 +153,8 @@ final int maxProfile = 4; // Three compact profiles plus full JRE MakefileProfiles(Properties p) { + // consider crypto, only if java/lang package exists + boolean foundJavaLang = false; for (int profile = 1; profile <= maxProfile; profile++) { String prefix = (profile < maxProfile ? "PROFILE_" + profile : "FULL_JRE"); String inclPackages = p.getProperty(prefix + "_RTJAR_INCLUDE_PACKAGES"); @@ -161,6 +163,8 @@ for (String pkg: inclPackages.substring(1).trim().split("\\s+")) { if (pkg.endsWith("/")) pkg = pkg.substring(0, pkg.length() - 1); + if (foundJavaLang == false && pkg.equals("java/lang")) + foundJavaLang = true; includePackage(profile, pkg); } String inclTypes = p.getProperty(prefix + "_RTJAR_INCLUDE_TYPES"); @@ -178,6 +182,15 @@ } } } + /* + * A hack to force javax/crypto package into the compact1 profile, + * because this package exists in jce.jar, and therefore not in + * ct.sym. Note javax/crypto should exist in a profile along with + * javax/net/ssl package. Thus, this package is added to compact1, + * implying that it should exist in all three profiles. + */ + if (foundJavaLang) + includePackage(1, "javax/crypto"); } @Override
--- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Thu May 29 13:46:36 2014 -0700 @@ -609,6 +609,9 @@ super.setPos(pos); return this; } + + public boolean isPoly() { return false; } + public boolean isStandalone() { return true; } } /** @@ -629,6 +632,9 @@ /** is this poly expression a 'true' poly expression? */ public PolyKind polyKind; + + @Override public boolean isPoly() { return polyKind == PolyKind.POLY; } + @Override public boolean isStandalone() { return polyKind == PolyKind.STANDALONE; } } /**
--- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -831,6 +831,8 @@ return symbol(((JCTypeApply) tree).clazz); case ANNOTATED_TYPE: return symbol(((JCAnnotatedType) tree).underlyingType); + case REFERENCE: + return ((JCMemberReference) tree).sym; default: return null; }
--- a/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,9 +56,9 @@ return null; } else { tree.accept(this); - JCTree result = this.result; + JCTree tmpResult = this.result; this.result = null; - return (T)result; // XXX cast + return (T)tmpResult; // XXX cast } }
--- a/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; import javax.tools.JavaFileManager.Location; @@ -67,6 +68,7 @@ final Messager messager; final JavadocClassReader javadocReader; final JavadocEnter javadocEnter; + final Set<JavaFileObject> uniquefiles; /** * Construct a new JavaCompiler processor, using appropriately @@ -77,6 +79,7 @@ messager = Messager.instance0(context); javadocReader = JavadocClassReader.instance0(context); javadocEnter = JavadocEnter.instance0(context); + uniquefiles = new HashSet<>(); } /** @@ -147,9 +150,7 @@ String name = it.head; if (!docClasses && fm != null && name.endsWith(".java") && new File(name).exists()) { JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next(); - docenv.notice("main.Loading_source_file", name); - JCCompilationUnit tree = parse(fo); - classTrees.append(tree); + parse(fo, classTrees, true); } else if (isValidPackageName(name)) { names = names.append(name); } else if (name.endsWith(".java")) { @@ -162,9 +163,7 @@ } } for (JavaFileObject fo: fileObjects) { - docenv.notice("main.Loading_source_file", fo.getName()); - JCCompilationUnit tree = parse(fo); - classTrees.append(tree); + parse(fo, classTrees, true); } if (!docClasses) { @@ -212,7 +211,7 @@ * .java files found in such a directory to args. */ private void parsePackageClasses(String name, - Iterable<JavaFileObject> files, + List<JavaFileObject> files, ListBuffer<JCCompilationUnit> trees, List<String> excludedPackages) throws IOException { @@ -220,7 +219,6 @@ return; } - boolean hasFiles = false; docenv.notice("main.Loading_source_files_for_package", name); if (files == null) { @@ -237,16 +235,22 @@ } files = lb.toList(); } + if (files.nonEmpty()) { + for (JavaFileObject fo : files) { + parse(fo, trees, false); + } + } else { + messager.warning(Messager.NOPOS, "main.no_source_files_for_package", + name.replace(File.separatorChar, '.')); + } + } - for (JavaFileObject fo : files) { - // messager.notice("main.Loading_source_file", fn); + private void parse(JavaFileObject fo, ListBuffer<JCCompilationUnit> trees, + boolean trace) { + if (uniquefiles.add(fo)) { // ignore duplicates + if (trace) + docenv.notice("main.Loading_source_file", fo.getName()); trees.append(parse(fo)); - hasFiles = true; - } - - if (!hasFiles) { - messager.warning(Messager.NOPOS, "main.no_source_files_for_package", - name.replace(File.separatorChar, '.')); } }
--- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java Thu May 29 13:46:36 2014 -0700 @@ -226,10 +226,7 @@ } public Void visitConstantValue(ConstantValue_attribute attr, Void ignore) { - if (options.compat) // BUG 6622216 javap names some attributes incorrectly - print("Constant value: "); - else - print("ConstantValue: "); + print("ConstantValue: "); constantWriter.write(attr.constantvalue_index); println(); return null; @@ -290,20 +287,10 @@ public Void visitInnerClasses(InnerClasses_attribute attr, Void ignore) { boolean first = true; - if (options.compat) { - writeInnerClassHeader(); - first = false; - } for (int i = 0 ; i < attr.classes.length; i++) { InnerClasses_attribute.Info info = attr.classes[i]; //access AccessFlags access_flags = info.inner_class_access_flags; - if (options.compat) { - // BUG 6622215: javap ignores certain relevant access flags - access_flags = access_flags.ignore(ACC_STATIC | ACC_PROTECTED | ACC_PRIVATE | ACC_INTERFACE | ACC_SYNTHETIC | ACC_ENUM); - // BUG 6622232: javap gets whitespace confused - print(" "); - } if (options.checkAccess(access_flags)) { if (first) { writeInnerClassHeader(); @@ -345,11 +332,7 @@ } private void writeInnerClassHeader() { - if (options.compat) // BUG 6622216: javap names some attributes incorrectly - print("InnerClass"); - else - print("InnerClasses"); - println(":"); + println("InnerClasses:"); indent(+1); } @@ -547,7 +530,6 @@ for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { w.write(entry); } - println(); indent(-1); return null; } @@ -559,7 +541,6 @@ for (StackMapTable_attribute.stack_map_frame entry : attr.entries) { w.write(entry); } - println(); indent(-1); return null; } @@ -571,14 +552,12 @@ } public Void visit_same_frame(StackMapTable_attribute.same_frame frame, Void p) { - printHeader(frame); - println(" /* same */"); + printHeader(frame, "/* same */"); return null; } public Void visit_same_locals_1_stack_item_frame(StackMapTable_attribute.same_locals_1_stack_item_frame frame, Void p) { - printHeader(frame); - println(" /* same_locals_1_stack_item */"); + printHeader(frame, "/* same_locals_1_stack_item */"); indent(+1); printMap("stack", frame.stack); indent(-1); @@ -586,8 +565,7 @@ } public Void visit_same_locals_1_stack_item_frame_extended(StackMapTable_attribute.same_locals_1_stack_item_frame_extended frame, Void p) { - printHeader(frame); - println(" /* same_locals_1_stack_item_frame_extended */"); + printHeader(frame, "/* same_locals_1_stack_item_frame_extended */"); indent(+1); println("offset_delta = " + frame.offset_delta); printMap("stack", frame.stack); @@ -596,8 +574,7 @@ } public Void visit_chop_frame(StackMapTable_attribute.chop_frame frame, Void p) { - printHeader(frame); - println(" /* chop */"); + printHeader(frame, "/* chop */"); indent(+1); println("offset_delta = " + frame.offset_delta); indent(-1); @@ -605,8 +582,7 @@ } public Void visit_same_frame_extended(StackMapTable_attribute.same_frame_extended frame, Void p) { - printHeader(frame); - println(" /* same_frame_extended */"); + printHeader(frame, "/* same_frame_extended */"); indent(+1); println("offset_delta = " + frame.offset_delta); indent(-1); @@ -614,21 +590,20 @@ } public Void visit_append_frame(StackMapTable_attribute.append_frame frame, Void p) { - printHeader(frame); - println(" /* append */"); + printHeader(frame, "/* append */"); indent(+1); println("offset_delta = " + frame.offset_delta); printMap("locals", frame.locals); + indent(-1); return null; } public Void visit_full_frame(StackMapTable_attribute.full_frame frame, Void p) { - printHeader(frame); if (frame instanceof StackMap_attribute.stack_map_frame) { + printHeader(frame, "offset = " + frame.offset_delta); indent(+1); - println(" offset = " + frame.offset_delta); } else { - println(" /* full_frame */"); + printHeader(frame, "/* full_frame */"); indent(+1); println("offset_delta = " + frame.offset_delta); } @@ -638,8 +613,9 @@ return null; } - void printHeader(StackMapTable_attribute.stack_map_frame frame) { - print(" frame_type = " + frame.frame_type); + void printHeader(StackMapTable_attribute.stack_map_frame frame, String extra) { + print("frame_type = " + frame.frame_type + " "); + println(extra); } void printMap(String name, StackMapTable_attribute.verification_type_info[] map) { @@ -710,10 +686,7 @@ } String toHex(byte b, int w) { - if (options.compat) // BUG 6622260: javap prints negative bytes incorrectly in hex - return toHex((int) b, w); - else - return toHex(b & 0xff, w); + return toHex(b & 0xff, w); } static String toHex(int i) {
--- a/src/share/classes/com/sun/tools/javap/BasicWriter.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/BasicWriter.java Thu May 29 13:46:36 2014 -0700 @@ -151,12 +151,22 @@ for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch (c) { + case ' ': + pendingSpaces++; + break; + case '\n': println(); break; + default: if (buffer.length() == 0) indent(); + if (pendingSpaces > 0) { + for (int sp = 0; sp < pendingSpaces; sp++) + buffer.append(' '); + pendingSpaces = 0; + } buffer.append(c); } } @@ -164,6 +174,8 @@ } protected void println() { + // ignore/discard pending spaces + pendingSpaces = 0; out.println(buffer); buffer.setLength(0); } @@ -173,26 +185,21 @@ } protected void tab() { - if (buffer.length() == 0) - indent(); - space(indentCount * indentWidth + tabColumn - buffer.length()); + int col = indentCount * indentWidth + tabColumn; + pendingSpaces += (col <= buffer.length() ? 1 : col - buffer.length()); } private void indent() { - space(indentCount * indentWidth); + pendingSpaces += (indentCount * indentWidth); } - private void space(int n) { - for (int i = 0; i < n; i++) - buffer.append(' '); - } - - private PrintWriter out; - private StringBuilder buffer; + private final PrintWriter out; + private final StringBuilder buffer; private int indentCount; - private int indentWidth; - private int tabColumn; + private final int indentWidth; + private final int tabColumn; private boolean pendingNewline; + private int pendingSpaces; } }
--- a/src/share/classes/com/sun/tools/javap/ClassWriter.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/ClassWriter.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -120,7 +120,7 @@ public void write(ClassFile cf) { setClassFile(cf); - if ((options.sysInfo || options.verbose) && !options.compat) { + if (options.sysInfo || options.verbose) { if (uri != null) { if (uri.getScheme().equals("file")) println("Classfile " + uri.getPath()); @@ -152,7 +152,7 @@ println("Compiled from \"" + getSourceFile((SourceFile_attribute) sfa) + "\""); } - if ((options.sysInfo || options.verbose) && !options.compat) { + if (options.sysInfo || options.verbose) { indent(-1); } @@ -202,11 +202,9 @@ if (options.verbose) { println(); indent(+1); - attrWriter.write(cf, cf.attributes, constant_pool); println("minor version: " + cf.minor_version); println("major version: " + cf.major_version); - if (!options.compat) - writeList("flags: ", flags.getClassFlags(), "\n"); + writeList("flags: ", flags.getClassFlags(), "\n"); indent(-1); constantWriter.writeConstantPool(); } else { @@ -219,6 +217,10 @@ writeMethods(); indent(-1); println("}"); + + if (options.verbose) { + attrWriter.write(cf, cf.attributes, constant_pool); + } } // where class JavaTypePrinter implements Type.Visitor<StringBuilder,StringBuilder> { @@ -372,7 +374,7 @@ } print(" "); print(getFieldName(f)); - if (options.showConstants && !options.compat) { // BUG 4111861 print static final field contents + if (options.showConstants) { Attribute a = f.attributes.get(Attribute.ConstantValue); if (a instanceof ConstantValue_attribute) { print(" = "); @@ -385,21 +387,23 @@ indent(+1); + boolean showBlank = false; + if (options.showDescriptors) println("descriptor: " + getValue(f.descriptor)); - if (options.verbose && !options.compat) + if (options.verbose) writeList("flags: ", flags.getFieldFlags(), "\n"); if (options.showAllAttrs) { for (Attribute attr: f.attributes) attrWriter.write(f, attr, constant_pool); - println(); + showBlank = true; } indent(-1); - if (options.showDisassembled || options.showLineAndLocalVariableTables) + if (showBlank || options.showDisassembled || options.showLineAndLocalVariableTables) println(); } @@ -485,7 +489,7 @@ println("descriptor: " + getValue(m.descriptor)); } - if (options.verbose && !options.compat) { + if (options.verbose) { writeList("flags: ", flags.getMethodFlags(), "\n"); } @@ -498,27 +502,23 @@ report("Unexpected or invalid value for Code attribute"); } - if (options.showDisassembled && !options.showAllAttrs) { - if (code != null) { + if (options.showAllAttrs) { + Attribute[] attrs = m.attributes.attrs; + for (Attribute attr: attrs) + attrWriter.write(m, attr, constant_pool); + } else if (code != null) { + if (options.showDisassembled) { println("Code:"); codeWriter.writeInstrs(code); codeWriter.writeExceptionTable(code); } - } - if (options.showLineAndLocalVariableTables) { - if (code != null) { + if (options.showLineAndLocalVariableTables) { attrWriter.write(code, code.attributes.get(Attribute.LineNumberTable), constant_pool); attrWriter.write(code, code.attributes.get(Attribute.LocalVariableTable), constant_pool); } } - if (options.showAllAttrs) { - Attribute[] attrs = m.attributes.attrs; - for (Attribute attr: attrs) - attrWriter.write(m, attr, constant_pool); - } - indent(-1); // set pendingNewline to write a newline before the next method (if any) @@ -555,13 +555,11 @@ } Signature_attribute getSignature(Attributes attributes) { - if (options.compat) // javap does not recognize recent attributes - return null; return (Signature_attribute) attributes.get(Attribute.Signature); } String adjustVarargs(AccessFlags flags, String params) { - if (flags.is(ACC_VARARGS) && !options.compat) { + if (flags.is(ACC_VARARGS)) { int i = params.lastIndexOf("[]"); if (i > 0) return params.substring(0, i) + "..." + params.substring(i+2);
--- a/src/share/classes/com/sun/tools/javap/ConstantWriter.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/ConstantWriter.java Thu May 29 13:46:36 2014 -0700 @@ -64,7 +64,7 @@ public Integer visitClass(CONSTANT_Class_info info, Void p) { print("#" + info.name_index); tab(); - println("// " + stringValue(info)); + println("// " + stringValue(info)); return 1; } @@ -76,7 +76,7 @@ public Integer visitFieldref(CONSTANT_Fieldref_info info, Void p) { print("#" + info.class_index + ".#" + info.name_and_type_index); tab(); - println("// " + stringValue(info)); + println("// " + stringValue(info)); return 1; } @@ -93,14 +93,14 @@ public Integer visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Void p) { print("#" + info.class_index + ".#" + info.name_and_type_index); tab(); - println("// " + stringValue(info)); + println("// " + stringValue(info)); return 1; } public Integer visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) { print("#" + info.bootstrap_method_attr_index + ":#" + info.name_and_type_index); tab(); - println("// " + stringValue(info)); + println("// " + stringValue(info)); return 1; } @@ -112,21 +112,21 @@ public Integer visitNameAndType(CONSTANT_NameAndType_info info, Void p) { print("#" + info.name_index + ":#" + info.type_index); tab(); - println("// " + stringValue(info)); + println("// " + stringValue(info)); return 1; } public Integer visitMethodref(CONSTANT_Methodref_info info, Void p) { print("#" + info.class_index + ".#" + info.name_and_type_index); tab(); - println("// " + stringValue(info)); + println("// " + stringValue(info)); return 1; } public Integer visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) { print("#" + info.reference_kind.tag + ":#" + info.reference_index); tab(); - println("// " + stringValue(info)); + println("// " + stringValue(info)); return 1; } @@ -140,7 +140,7 @@ public Integer visitString(CONSTANT_String_info info, Void p) { print("#" + info.string_index); tab(); - println("// " + stringValue(info)); + println("// " + stringValue(info)); return 1; }
--- a/src/share/classes/com/sun/tools/javap/JavapTask.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Thu May 29 13:46:36 2014 -0700 @@ -195,48 +195,12 @@ } }, -// new Option(false, "-all") { -// void process(JavapTask task, String opt, String arg) { -// task.options.showAllAttrs = true; -// } -// }, - - new Option(false, "-h") { - void process(JavapTask task, String opt, String arg) throws BadArgs { - throw task.new BadArgs("err.h.not.supported"); - } - }, - - new Option(false, "-verify", "-verify-verbose") { - void process(JavapTask task, String opt, String arg) throws BadArgs { - throw task.new BadArgs("err.verify.not.supported"); - } - }, - new Option(false, "-sysinfo") { void process(JavapTask task, String opt, String arg) { task.options.sysInfo = true; } }, - new Option(false, "-Xold") { - void process(JavapTask task, String opt, String arg) throws BadArgs { - task.log.println(task.getMessage("warn.Xold.not.supported")); - } - }, - - new Option(false, "-Xnew") { - void process(JavapTask task, String opt, String arg) throws BadArgs { - // ignore: this _is_ the new version - } - }, - - new Option(false, "-XDcompat") { - void process(JavapTask task, String opt, String arg) { - task.options.compat = true; - } - }, - new Option(false, "-XDdetails") { void process(JavapTask task, String opt, String arg) { task.options.details = EnumSet.allOf(InstructionDetailWriter.Kind.class); @@ -309,7 +273,9 @@ void process(JavapTask task, String opt, String arg) throws BadArgs { int sep = opt.indexOf(":"); try { - task.options.indentWidth = Integer.valueOf(opt.substring(sep + 1)); + int i = Integer.valueOf(opt.substring(sep + 1)); + if (i > 0) // silently ignore invalid values + task.options.indentWidth = i; } catch (NumberFormatException e) { } } @@ -325,7 +291,9 @@ void process(JavapTask task, String opt, String arg) throws BadArgs { int sep = opt.indexOf(":"); try { - task.options.tabColumn = Integer.valueOf(opt.substring(sep + 1)); + int i = Integer.valueOf(opt.substring(sep + 1)); + if (i > 0) // silently ignore invalid values + task.options.tabColumn = i; } catch (NumberFormatException e) { } } @@ -466,7 +434,7 @@ } catch (BadArgs e) { reportError(e.key, e.args); if (e.showUsage) { - log.println(getMessage("main.usage.summary", progname)); + printLines(getMessage("main.usage.summary", progname)); } return EXIT_CMDERR; } catch (InternalError e) { @@ -520,7 +488,7 @@ throw new BadArgs("err.unknown.option", arg).showUsage(true); } - if (!options.compat && options.accessOptions.size() > 1) { + if (options.accessOptions.size() > 1) { StringBuilder sb = new StringBuilder(); for (String opt: options.accessOptions) { if (sb.length() > 0) @@ -561,8 +529,12 @@ } } - if (fileManager.handleOption(name, rest)) - return; + try { + if (fileManager.handleOption(name, rest)) + return; + } catch (IllegalArgumentException e) { + throw new BadArgs("err.invalid.use.of.option", name).showUsage(true); + } throw new BadArgs("err.unknown.option", name).showUsage(true); } @@ -581,8 +553,6 @@ SourceWriter sourceWriter = SourceWriter.instance(context); sourceWriter.setFileManager(fileManager); - attributeFactory.setCompat(options.compat); - int result = EXIT_OK; for (String className: classes) { @@ -878,27 +848,33 @@ } private void showHelp() { - log.println(getMessage("main.usage", progname)); + printLines(getMessage("main.usage", progname)); for (Option o: recognizedOptions) { String name = o.aliases[0].substring(1); // there must always be at least one name if (name.startsWith("X") || name.equals("fullversion") || name.equals("h") || name.equals("verify")) continue; - log.println(getMessage("main.opt." + name)); + printLines(getMessage("main.opt." + name)); } String[] fmOptions = { "-classpath", "-cp", "-bootclasspath" }; for (String o: fmOptions) { if (fileManager.isSupportedOption(o) == -1) continue; String name = o.substring(1); - log.println(getMessage("main.opt." + name)); + printLines(getMessage("main.opt." + name)); } } private void showVersion(boolean full) { - log.println(version(full ? "full" : "release")); + printLines(version(full ? "full" : "release")); } + private void printLines(String msg) { + log.println(msg.replace("\n", nl)); + } + + private static final String nl = System.getProperty("line.separator"); + private static final String versionRBName = "com.sun.tools.javap.resources.version"; private static ResourceBundle versionRB;
--- a/src/share/classes/com/sun/tools/javap/Options.java Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/Options.java Thu May 29 13:46:36 2014 -0700 @@ -86,8 +86,6 @@ public boolean showConstants; public boolean sysInfo; public boolean showInnerClasses; - public int indentWidth = 2; // #spaces per indentWidth level - public int tabColumn = 40; // column number for comments - - public boolean compat; // bug-for-bug compatibility mode with old javap + public int indentWidth = 2; // #spaces per indentWidth level; must be > 0 + public int tabColumn = 40; // column number for comments; must be > 0 }
--- a/src/share/classes/com/sun/tools/javap/resources/javap.properties Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/resources/javap.properties Thu May 29 13:46:36 2014 -0700 @@ -6,7 +6,6 @@ err.crash=A serious internal error has occurred: {0}\nPlease file a bug report, and include the following information:\n{1} err.end.of.file=unexpected end of file while reading {0} err.file.not.found=file not found: {0} -err.h.not.supported=-h is no longer available - use the 'javah' program err.incompatible.options=bad combination of options: {0} err.internal.error=internal error: {0} {1} {2} err.invalid.arg.for.option=invalid argument for option: {0} @@ -14,12 +13,11 @@ err.missing.arg=no value given for {0} err.no.classes.specified=no classes specified err.not.standard.file.manager=can only specify class files when using a standard file manager +err.invalid.use.of.option=invalid use of option: {0} err.unknown.option=unknown option: {0} -err.verify.not.supported=-verify not supported err.no.SourceFile.attribute=no SourceFile attribute err.source.file.not.found=source file not found err.bad.innerclasses.attribute=bad InnerClasses attribute for {0} -warn.Xold.not.supported=-Xold is no longer available main.usage.summary=\ Usage: {0} <options> <classes>\n\ @@ -80,7 +78,7 @@ \ -bootclasspath <path> Override location of bootstrap class files main.opt.constants=\ -\ -constants Show static final constants +\ -constants Show final constants main.opt.sysinfo=\
--- a/src/share/classes/com/sun/tools/javap/resources/javap_ja.properties Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/resources/javap_ja.properties Thu May 29 13:46:36 2014 -0700 @@ -3,10 +3,9 @@ err.bad.constant.pool={0}\u306E\u5B9A\u6570\u30D7\u30FC\u30EB\u306E\u8AAD\u53D6\u308A\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: {1} err.class.not.found=\u30AF\u30E9\u30B9\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: {0} -err.crash=\u91CD\u5927\u306A\u5185\u90E8\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: {0}\n\u6B21\u306E\u60C5\u5831\u3092\u542B\u3080\u30D0\u30B0\u30FB\u30EC\u30DD\u30FC\u30C8\u3092\u30D5\u30A1\u30A4\u30EB\u3057\u3066\u304F\u3060\u3055\u3044:\n{1} +err.crash=\u91CD\u5927\u306A\u5185\u90E8\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: {0}\n\u6B21\u306E\u60C5\u5831\u3092\u542B\u3080bug\u30EC\u30DD\u30FC\u30C8\u3092\u30D5\u30A1\u30A4\u30EB\u3057\u3066\u304F\u3060\u3055\u3044:\n{1} err.end.of.file={0}\u306E\u8AAD\u53D6\u308A\u4E2D\u306B\u4E88\u671F\u3057\u306A\u3044\u30D5\u30A1\u30A4\u30EB\u306E\u7D42\u308F\u308A\u304C\u691C\u51FA\u3055\u308C\u307E\u3057\u305F err.file.not.found=\u30D5\u30A1\u30A4\u30EB\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: {0} -err.h.not.supported=-h\u306F\u4F7F\u7528\u53EF\u80FD\u3067\u306A\u304F\u306A\u308A\u307E\u3057\u305F - 'javah'\u30D7\u30ED\u30B0\u30E9\u30E0\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044 err.incompatible.options=\u30AA\u30D7\u30B7\u30E7\u30F3\u306E\u7D44\u5408\u305B\u304C\u4E0D\u6B63\u3067\u3059: {0} err.internal.error=\u5185\u90E8\u30A8\u30E9\u30FC: {0} {1} {2} err.invalid.arg.for.option=\u30AA\u30D7\u30B7\u30E7\u30F3\u306E\u5F15\u6570\u304C\u7121\u52B9\u3067\u3059: {0} @@ -14,12 +13,11 @@ err.missing.arg={0}\u306B\u5024\u304C\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093 err.no.classes.specified=\u30AF\u30E9\u30B9\u304C\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093 err.not.standard.file.manager=\u6A19\u6E96\u30D5\u30A1\u30A4\u30EB\u30FB\u30DE\u30CD\u30FC\u30B8\u30E3\u3092\u4F7F\u7528\u3057\u3066\u3044\u308B\u5834\u5408\u306F\u30AF\u30E9\u30B9\u30FB\u30D5\u30A1\u30A4\u30EB\u306E\u307F\u6307\u5B9A\u3067\u304D\u307E\u3059 +err.invalid.use.of.option=\u30AA\u30D7\u30B7\u30E7\u30F3\u306E\u4F7F\u7528\u304C\u7121\u52B9\u3067\u3059: {0} err.unknown.option=\u4E0D\u660E\u306A\u30AA\u30D7\u30B7\u30E7\u30F3: {0} -err.verify.not.supported=-verify\u306F\u30B5\u30DD\u30FC\u30C8\u3055\u308C\u3066\u3044\u307E\u305B\u3093 err.no.SourceFile.attribute=SourceFile\u5C5E\u6027\u304C\u3042\u308A\u307E\u305B\u3093 err.source.file.not.found=\u30BD\u30FC\u30B9\u30FB\u30D5\u30A1\u30A4\u30EB\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093 err.bad.innerclasses.attribute={0}\u306EInnerClasses\u5C5E\u6027\u304C\u4E0D\u6B63\u3067\u3059 -warn.Xold.not.supported=-Xold\u306F\u4F7F\u7528\u3067\u304D\u306A\u304F\u306A\u308A\u307E\u3057\u305F main.usage.summary=\u4F7F\u7528\u65B9\u6CD5: {0} <options> <classes>\n\u4F7F\u7528\u53EF\u80FD\u306A\u30AA\u30D7\u30B7\u30E7\u30F3\u306E\u30EA\u30B9\u30C8\u306B\u3064\u3044\u3066\u306F\u3001-help\u3092\u4F7F\u7528\u3057\u307E\u3059 @@ -57,9 +55,9 @@ main.opt.cp=\ -cp <path> \u30E6\u30FC\u30B6\u30FC\u30FB\u30AF\u30E9\u30B9\u30FB\u30D5\u30A1\u30A4\u30EB\u3092\u691C\u7D22\u3059\u308B\u5834\u6240\u3092\u6307\u5B9A\u3059\u308B -main.opt.bootclasspath=\ -bootclasspath <path> \u30D6\u30FC\u30C8\u30B9\u30C8\u30E9\u30C3\u30D7\u30FB\u30AF\u30E9\u30B9\u30FB\u30D5\u30A1\u30A4\u30EB\u306E\u4F4D\u7F6E\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3059\u308B +main.opt.bootclasspath=\ -bootclasspath <path> \u30D6\u30FC\u30C8\u30B9\u30C8\u30E9\u30C3\u30D7\u30FB\u30AF\u30E9\u30B9\u30FB\u30D5\u30A1\u30A4\u30EB\u306E\u5834\u6240\u3092\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9\u3059\u308B -main.opt.constants=\ -constants \u9759\u7684final\u5B9A\u6570\u3092\u8868\u793A\u3059\u308B +main.opt.constants=\ -constants final\u5B9A\u6570\u3092\u8868\u793A\u3059\u308B main.opt.sysinfo=\ -sysinfo \u51E6\u7406\u3057\u3066\u3044\u308B\u30AF\u30E9\u30B9\u306E\u30B7\u30B9\u30C6\u30E0\u60C5\u5831(\u30D1\u30B9\u3001\u30B5\u30A4\u30BA\u3001\u65E5\u4ED8\u3001MD5\u30CF\u30C3\u30B7\u30E5)\n \u3092\u8868\u793A\u3059\u308B
--- a/src/share/classes/com/sun/tools/javap/resources/javap_zh_CN.properties Mon May 19 22:00:11 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/resources/javap_zh_CN.properties Thu May 29 13:46:36 2014 -0700 @@ -6,7 +6,6 @@ err.crash=\u51FA\u73B0\u4E25\u91CD\u7684\u5185\u90E8\u9519\u8BEF: {0}\n\u8BF7\u5EFA\u7ACB Bug \u62A5\u544A, \u5E76\u5305\u62EC\u4EE5\u4E0B\u4FE1\u606F:\n{1} err.end.of.file=\u8BFB\u53D6{0}\u65F6\u51FA\u73B0\u610F\u5916\u7684\u6587\u4EF6\u7ED3\u5C3E err.file.not.found=\u627E\u4E0D\u5230\u6587\u4EF6: {0} -err.h.not.supported=-h \u4E0D\u518D\u53EF\u7528 - \u8BF7\u4F7F\u7528 'javah' \u7A0B\u5E8F err.incompatible.options=\u9009\u9879\u7EC4\u5408\u9519\u8BEF: {0} err.internal.error=\u5185\u90E8\u9519\u8BEF: {0} {1} {2} err.invalid.arg.for.option=\u9009\u9879\u7684\u53C2\u6570\u65E0\u6548: {0} @@ -14,12 +13,11 @@ err.missing.arg=\u6CA1\u6709\u4E3A{0}\u6307\u5B9A\u503C err.no.classes.specified=\u672A\u6307\u5B9A\u7C7B err.not.standard.file.manager=\u4F7F\u7528\u6807\u51C6\u6587\u4EF6\u7BA1\u7406\u5668\u65F6\u53EA\u80FD\u6307\u5B9A\u7C7B\u6587\u4EF6 +err.invalid.use.of.option=\u9009\u9879\u7684\u4F7F\u7528\u65E0\u6548: {0} err.unknown.option=\u672A\u77E5\u9009\u9879: {0} -err.verify.not.supported=\u4E0D\u652F\u6301 -verify err.no.SourceFile.attribute=\u6CA1\u6709 SourceFile \u5C5E\u6027 err.source.file.not.found=\u627E\u4E0D\u5230\u6E90\u6587\u4EF6 err.bad.innerclasses.attribute={0}\u7684 InnerClasses \u5C5E\u6027\u9519\u8BEF -warn.Xold.not.supported=-Xold \u4E0D\u518D\u53EF\u7528 main.usage.summary=\u7528\u6CD5: {0} <options> <classes>\n\u4F7F\u7528 -help \u5217\u51FA\u53EF\u80FD\u7684\u9009\u9879 @@ -59,7 +57,7 @@ main.opt.bootclasspath=\ -bootclasspath <path> \u8986\u76D6\u5F15\u5BFC\u7C7B\u6587\u4EF6\u7684\u4F4D\u7F6E -main.opt.constants=\ -constants \u663E\u793A\u9759\u6001\u6700\u7EC8\u5E38\u91CF +main.opt.constants=\ -constants \u663E\u793A\u6700\u7EC8\u5E38\u91CF main.opt.sysinfo=\ -sysinfo \u663E\u793A\u6B63\u5728\u5904\u7406\u7684\u7C7B\u7684\n \u7CFB\u7EDF\u4FE1\u606F (\u8DEF\u5F84, \u5927\u5C0F, \u65E5\u671F, MD5 \u6563\u5217)
--- a/test/Makefile Mon May 19 22:00:11 2014 -0700 +++ b/test/Makefile Thu May 29 13:46:36 2014 -0700 @@ -186,6 +186,12 @@ JTREG_OPTIONS += -timeoutFactor:$(JTREG_TIMEOUT_FACTOR) endif +# Default verbosity setting for jtreg +JTREG_VERBOSE = fail,error,nopass + +# Default verbosity setting for jck +JCK_VERBOSE = non-pass + # Assertions: some tests show failures when assertions are enabled. # Since javac is typically loaded via the bootclassloader (either via TESTJAVA # or TESTBOOTCLASSPATH), you may need -esa to enable assertions in javac. @@ -256,6 +262,8 @@ # Version of java used to run jtreg. Should normally be the same as TESTJAVA # TESTJAVA # Version of java to be tested. +# JTREG_VERBOSE +# Verbosity setting for jtreg # JTREG_OPTIONS # Additional options for jtreg # JTREG_TESTDIRS @@ -273,7 +281,7 @@ JT_JAVA=$(JT_JAVA) $(JTREG) \ -J-Xmx512m \ -vmoption:-Xmx768m \ - -a -ignore:quiet -v:fail,error,nopass \ + -a -ignore:quiet $(if $(JTREG_VERBOSE),-v:$(JTREG_VERBOSE)) \ -r:$(JTREG_OUTPUT_DIR)/JTreport \ -w:$(JTREG_OUTPUT_DIR)/JTwork \ -jdk:$(TESTJAVA) \ @@ -312,6 +320,8 @@ # Default is JDK 7 # TESTJAVA # Version of java to be tested. +# JCK_VERBOSE +# Verbosity setting for jtjck # JCK_COMPILER_OPTIONS # Additional options for JCK-compiler # JCK_COMPILER_TESTDIRS @@ -325,9 +335,9 @@ @rm -f -r $(JCK_COMPILER_OUTPUT_DIR)/work $(JCK_COMPILER_OUTPUT_DIR)/report \ $(JCK_COMPILER_OUTPUT_DIR)/diff.html $(JCK_COMPILER_OUTPUT_DIR)/status.txt @mkdir -p $(JCK_COMPILER_OUTPUT_DIR) - $(JT_JAVA)/bin/java -XX:MaxPermSize=256m -Xmx512m \ + $(JT_JAVA)/bin/java -Xmx512m \ -jar $(JCK_HOME)/JCK-compiler-8/lib/jtjck.jar \ - -v:non-pass \ + $(if $(JCK_VERBOSE),-v:$(JCK_VERBOSE)) \ -r:$(JCK_COMPILER_OUTPUT_DIR)/report \ -w:$(JCK_COMPILER_OUTPUT_DIR)/work \ -jdk:$(TESTJAVA) \ @@ -361,6 +371,8 @@ # Version of java used to run JCK. Should normally be the same as TESTJAVA # TESTJAVA # Version of java to be tested. +# JCK_VERBOSE +# Verbosity setting for jtjck # JCK_RUNTIME_OPTIONS # Additional options for JCK-runtime # JCK_RUNTIME_TESTDIRS @@ -374,9 +386,9 @@ @rm -f -r $(JCK_RUNTIME_OUTPUT_DIR)/work $(JCK_RUNTIME_OUTPUT_DIR)/report \ $(JCK_RUNTIME_OUTPUT_DIR)/diff.html $(JCK_RUNTIME_OUTPUT_DIR)/status.txt @mkdir -p $(JCK_RUNTIME_OUTPUT_DIR) - $(JT_JAVA)/bin/java -XX:MaxPermSize=256m -Xmx512m \ + $(JT_JAVA)/bin/java -Xmx512m \ -jar $(JCK_HOME)/JCK-runtime-8/lib/jtjck.jar \ - -v:non-pass \ + $(if $(JCK_VERBOSE),-v:$(JCK_VERBOSE)) \ -r:$(JCK_RUNTIME_OUTPUT_DIR)/report \ -w:$(JCK_RUNTIME_OUTPUT_DIR)/work \ -jdk:$(TESTJAVA) \
--- a/test/com/sun/javadoc/testLinkOption/TestLinkOption.java Mon May 19 22:00:11 2014 -0700 +++ b/test/com/sun/javadoc/testLinkOption/TestLinkOption.java Thu May 29 13:46:36 2014 -0700 @@ -23,18 +23,20 @@ /* * @test - * @bug 4720957 5020118 8026567 + * @bug 4720957 5020118 8026567 8038976 * @summary Test to make sure that -link and -linkoffline link to - * right files. + * right files, and URLs with and without trailing slash are accepted. * @author jamieh * @library ../lib/ * @build JavadocTester TestLinkOption * @run main TestLinkOption */ +import java.io.File; + public class TestLinkOption extends JavadocTester { - private static final String BUG_ID = "4720957-5020118"; + private static final String BUG_ID = "4720957-5020118-8038976"; //Generate the documentation using -linkoffline and a URL as the first parameter. private static final String[] ARGS1 = new String[] { @@ -83,7 +85,34 @@ } }; private static final String[][] NEGATED_TEST2 = NO_TEST; - + /* + * Create the documentation using the -link option, vary the behavior with + * both trailing and no trailing slash. We are only interested in ensuring + * that the command executes with no errors or related warnings. + */ + static String[] createArguments(boolean withTrailingSlash) { + String packagePath = new File(BUG_ID + "-1").getAbsolutePath(); + String outputDirName = BUG_ID; + if (withTrailingSlash) { + // add the trailing slash, if it is not present! + if (!packagePath.endsWith(FS)) { + packagePath = packagePath + FS; + } + outputDirName = outputDirName + "-3"; + } else { + // remove the trailing slash, if it is present! + if (packagePath.endsWith(FS)) { + packagePath = packagePath.substring(0, packagePath.length() - 1); + } + outputDirName = outputDirName + "-4"; + } + String args[] = { + "-d", outputDirName, "-sourcepath", SRC_DIR, + "-link", "file:///" + packagePath, "-package", "pkg2" + }; + System.out.println("packagePath: " + packagePath); + return args; + } /** * The entry point of the test. * @param args the array of command line arguments. @@ -92,6 +121,12 @@ TestLinkOption tester = new TestLinkOption(); run(tester, ARGS1, TEST1, NEGATED_TEST1); run(tester, ARGS2, TEST2, NEGATED_TEST2); + tester.runJavadoc(createArguments(true)); // with trailing slash + tester.runJavadoc(createArguments(false)); // without trailing slash + tester.printSummary(); + if (tester.getWarningOutput().contains("warning - Error fetching URL")) { + throw new Error("URL rejected ?"); + } tester.printSummary(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/AnonymousSubclassTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8023945 + * @summary javac wrongly allows a subclass of an anonymous class + * @library /tools/javac/lib + * @build ToolBox + * @run main AnonymousSubclassTest + */ + +import java.util.ArrayList; +import java.io.IOException; + +public class AnonymousSubclassTest { + public static void main(String... args) throws Exception { + new AnonymousSubclassTest().run(); + } + + // To trigger the error we want, first we need to compile + // a class with an anonymous inner class: Foo$1. + final String foo = + "public class Foo {" + + " void m() { Foo f = new Foo() {}; }" + + "}"; + + // Then, we try to subclass the anonymous class + // Note: we must do this in two classes because a different + // error will be generated if we don't load Foo$1 through the + // class reader. + final String test1 = + "public class Test1 {" + + " void m() {"+ + " Foo f1 = new Foo();"+ + " Foo f2 = new Foo$1(f1) {};"+ + " }" + + "}"; + + final String test2 = + "public class Test2 {" + + " class T extends Foo$1 {" + + " public T(Foo f) { super(f); }" + + " }"+ + "}"; + + void compOk(String code) throws Exception { + ToolBox.javac(new ToolBox.JavaToolArgs().setSources(code)); + } + + void compFail(String code) throws Exception { + ArrayList<String> errors = new ArrayList<>(); + ToolBox.JavaToolArgs args = new ToolBox.JavaToolArgs(); + args.setSources(code) + .appendArgs("-cp", ".", "-XDrawDiagnostics") + .set(ToolBox.Expect.FAIL) + .setErrOutput(errors); + ToolBox.javac(args); + + if (!errors.get(0).contains("cant.inherit.from.anon")) { + System.out.println(errors.get(0)); + throw new Exception("test failed"); + } + } + + void run() throws Exception { + compOk(foo); + compFail(test1); + compFail(test2); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/DefiniteAssignment/T8039026.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,21 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8039026 + * @summary Definitely unassigned field can be accessed + * @compile/fail/ref=T8039026.out -XDrawDiagnostics T8039026.java + */ + +public class T8039026 { + final int x,y,z; + final int a = this.y; // <- error + { + int b = true ? this.x : 0; // <- error + System.out.println(this.x); // <- error + this.y = 1; + } + T8039026() { + this.x = 1; // <- no error! + this.y = 1; // <- error + this.z = this.x; // <- no error + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/DefiniteAssignment/T8039026.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,4 @@ +T8039026.java:10:23: compiler.err.var.might.not.have.been.initialized: y +T8039026.java:12:28: compiler.err.var.might.not.have.been.initialized: x +T8039026.java:18:13: compiler.err.var.might.already.be.assigned: y +3 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/IncorrectInheritance/IncorrectInheritanceTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8034924 + * @summary Incorrect inheritance of inaccessible static method + * @library /tools/javac/lib + * @build ToolBox + * @run main IncorrectInheritanceTest + */ + +public class IncorrectInheritanceTest { + private static final String ASrc = + "package pkg;\n" + + "\n" + + "public class A {\n" + + " static void foo(Object o) {}\n" + + " private static void bar(Object o) {}\n" + + "}"; + + private static final String BSrc = + "import pkg.A;\n" + + "class B extends A {\n" + + " public void foo(Object o) {}\n" + + " public void bar(Object o) {}\n" + + "}"; + + private static final String CSrc = + "class C extends B {\n" + + " public void m(Object o) {\n" + + " foo(o);\n" + + " bar(o);\n" + + " }\n" + + "}"; + + public static void main(String[] args) throws Exception { + new IncorrectInheritanceTest().test(); + } + + public void test() throws Exception { + ToolBox.JavaToolArgs javacParams = + new ToolBox.JavaToolArgs() + .setSources(ASrc, BSrc, CSrc); + ToolBox.javac(javacParams); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8029002/MultipleUpperBoundsIncorporationTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8029002 + * @summary javac should take multiple upper bounds into account in incorporation + * @compile MultipleUpperBoundsIncorporationTest.java + */ + +import java.util.ArrayList; +import java.util.List; + +public class MultipleUpperBoundsIncorporationTest { + + static class TestCase1 { + interface Task<E extends Exception> {} + + class Comparator<T> {} + + class CustomException extends Exception {} + + class TaskQueue<E extends Exception, T extends Task<E>> {} + + abstract class Test { + abstract <E extends Exception, T extends Task<E>> TaskQueue<E, T> create(Comparator<? super T> comparator); + + void f(Comparator<Task<CustomException>> comp) { + TaskQueue<CustomException, Task<CustomException>> queue = create(comp); + queue.getClass(); + } + } + } + + static class TestCase2 { + public <T, E extends List<T>> E typedNull() { + return null; + } + + public void call() { + ArrayList<String> list = typedNull(); + } + } + + static class TestCase3 { + interface I extends Iterable<String> {} + + <T, Exp extends Iterable<T>> Exp typedNull() { return null; } + I i = typedNull(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8029102/WarnSerializableLambdaTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,241 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8029102 + * @summary Enhance compiler warnings for Lambda + * Checks that the warning for accessing non public members of a class is + * fired correctly. + * @compile/fail/ref=WarnSerializableLambdaTest.out -XDrawDiagnostics -Werror -XDwarnOnAccessToSensitiveMembers WarnSerializableLambdaTest.java + */ + +import java.io.Serializable; + +public class WarnSerializableLambdaTest { + + void warnLambda() throws Exception { + SAM t3 = (SAM & Serializable)WarnSerializableLambdaTest::packageClassMethod; + SAM t4 = (SAM & Serializable)WarnSerializableLambdaTest::protectedClassMethod; + SAM t5 = (SAM & Serializable)WarnSerializableLambdaTest::privateClassMethod; + + WarnSerializableLambdaTest test = new WarnSerializableLambdaTest(); + SAM t6 = (SAM & Serializable)test::packageInstanceMethod; + SAM t7 = (SAM & Serializable)test::protectedInstanceMethod; + SAM t8 = (SAM & Serializable)test::privateInstanceMethod; + + SAM t9 = (SAM & Serializable) c -> { + + WarnSerializableLambdaTest.staticPackageField = ""; + WarnSerializableLambdaTest.staticProtectedField = ""; + WarnSerializableLambdaTest.staticPrivateField = ""; + + packageField = ""; + protectedField = ""; + privateField = ""; + + WarnSerializableLambdaTest.packageClassMethod(null); + WarnSerializableLambdaTest.protectedClassMethod(null); + WarnSerializableLambdaTest.privateClassMethod(null); + + packageInstanceMethod(null); + protectedInstanceMethod(null); + privateInstanceMethod(null); + + PrivateClass.effectivelyNonPublicStaticField = ""; + PrivateClass.effectivelyNonPublicClassMethod(); + + PrivateClass p = new PrivateClass(); + p.effectivelyNonPublicInstanceField = ""; + p.effectivelyNonPublicInstanceMethod(); + + return null; + }; + } + + private void warnAnoInnerClass() throws Exception { + new SerializableDesc() { + public void m(Object param) throws Exception { + WarnSerializableLambdaTest.staticPackageField = ""; + WarnSerializableLambdaTest.staticProtectedField = ""; + WarnSerializableLambdaTest.staticPrivateField = ""; + + packageField = ""; + protectedField = ""; + privateField = ""; + + WarnSerializableLambdaTest.packageClassMethod(null); + WarnSerializableLambdaTest.protectedClassMethod(null); + WarnSerializableLambdaTest.privateClassMethod(null); + + packageInstanceMethod(null); + protectedInstanceMethod(null); + privateInstanceMethod(null); + + PrivateClass.effectivelyNonPublicStaticField = ""; + PrivateClass.effectivelyNonPublicClassMethod(); + + PrivateClass p = new PrivateClass(); + p.effectivelyNonPublicInstanceField = ""; + p.effectivelyNonPublicInstanceMethod(); + } + }; + } + + void dontWarnLambda() throws Exception { + SAM t1 = (SAM & Serializable)WarnSerializableLambdaTest::publicClassMethod; + + WarnSerializableLambdaTest test = new WarnSerializableLambdaTest(); + SAM t2 = (SAM & Serializable)test::publicInstanceMethod; + + int[] buffer = {0}; + + SAM t3 = (SAM & Serializable) param -> { + Object localVar; + localVar = null; + param = null; + + WarnSerializableLambdaTest.staticPublicField = ""; + publicField = ""; + WarnSerializableLambdaTest.publicClassMethod(null); + publicInstanceMethod(null); + + PublicClass.effectivelyPublicStaticField = ""; + PublicClass.effectivelyPublicClassMethod(); + + PublicClass p = new PublicClass(); + p.effectivelyPublicInstanceField = ""; + p.effectivelyPublicInstanceMethod(); + + int l = buffer.length; + + return null; + }; + } + + private void dontWarnAnoInnerClass() throws Exception { + final int[] buffer = {0}; + new SerializableDesc() { + public void m(Object param) throws Exception { + Object localVar; + localVar = null; + param = null; + + WarnSerializableLambdaTest.staticPublicField = ""; + publicField = ""; + WarnSerializableLambdaTest.publicClassMethod(null); + publicInstanceMethod(null); + + PublicClass.effectivelyPublicStaticField = ""; + PublicClass.effectivelyPublicClassMethod(); + + PublicClass p = new PublicClass(); + p.effectivelyPublicInstanceField = ""; + p.effectivelyPublicInstanceMethod(); + + int l = buffer.length; + } + }; + } + + enum WarnEnum { + A { + public void m() throws Exception { + WarnSerializableLambdaTest.staticPackageField = ""; + WarnSerializableLambdaTest.staticProtectedField = ""; + WarnSerializableLambdaTest.staticPrivateField = ""; + + WarnSerializableLambdaTest test = + new WarnSerializableLambdaTest(); + + test.packageField = ""; + test.protectedField = ""; + test.privateField = ""; + + WarnSerializableLambdaTest.packageClassMethod(null); + WarnSerializableLambdaTest.protectedClassMethod(null); + WarnSerializableLambdaTest.privateClassMethod(null); + + test.packageInstanceMethod(null); + test.protectedInstanceMethod(null); + test.privateInstanceMethod(null); + + PrivateClass.effectivelyNonPublicStaticField = ""; + PrivateClass.effectivelyNonPublicClassMethod(); + + PrivateClass p = new PrivateClass(); + p.effectivelyNonPublicInstanceField = ""; + p.effectivelyNonPublicInstanceMethod(); + } + }; + + public void m() throws Exception {} + } + + static String staticPackageField; + static private String staticPrivateField; + static protected String staticProtectedField; + static public String staticPublicField; + + String packageField; + private String privateField; + protected String protectedField; + public String publicField; + + static Object packageClassMethod(String s) { + return null; + } + + static private Object privateClassMethod(String s) { + return null; + } + + static protected Object protectedClassMethod(String s) { + return null; + } + + static public Object publicClassMethod(String s) { + return null; + } + + Object packageInstanceMethod(String s) { + return null; + } + + protected Object protectedInstanceMethod(String s) { + return null; + } + + private Object privateInstanceMethod(String s) { + return null; + } + + public Object publicInstanceMethod(String s) { + return null; + } + + interface SAM { + Object apply(String s) throws Exception; + } + + interface SAM2 { + Object apply(String arg1, String arg2); + } + + class SerializableDesc implements Serializable { + public void m(Object param) throws Exception {} + } + + static private class PrivateClass { + static public String effectivelyNonPublicStaticField; + public String effectivelyNonPublicInstanceField; + + static public void effectivelyNonPublicClassMethod() {} + public void effectivelyNonPublicInstanceMethod() {} + } + + static public class PublicClass { + static public String effectivelyPublicStaticField; + public String effectivelyPublicInstanceField; + + static public void effectivelyPublicClassMethod() {} + public void effectivelyPublicInstanceMethod() {} + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8029102/WarnSerializableLambdaTest.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,57 @@ +WarnSerializableLambdaTest.java:15:38: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:16:38: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:17:38: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:20:38: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:21:38: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:22:38: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:26:39: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPackageField +WarnSerializableLambdaTest.java:27:39: compiler.warn.access.to.sensitive.member.from.serializable.element: staticProtectedField +WarnSerializableLambdaTest.java:28:39: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPrivateField +WarnSerializableLambdaTest.java:30:13: compiler.warn.access.to.sensitive.member.from.serializable.element: packageField +WarnSerializableLambdaTest.java:31:13: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedField +WarnSerializableLambdaTest.java:32:13: compiler.warn.access.to.sensitive.member.from.serializable.element: privateField +WarnSerializableLambdaTest.java:34:39: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:35:39: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:36:39: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:38:13: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:39:13: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:40:13: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:42:25: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicStaticField +WarnSerializableLambdaTest.java:43:25: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicClassMethod() +WarnSerializableLambdaTest.java:46:14: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceField +WarnSerializableLambdaTest.java:47:14: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceMethod() +WarnSerializableLambdaTest.java:56:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPackageField +WarnSerializableLambdaTest.java:57:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticProtectedField +WarnSerializableLambdaTest.java:58:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPrivateField +WarnSerializableLambdaTest.java:60:17: compiler.warn.access.to.sensitive.member.from.serializable.element: packageField +WarnSerializableLambdaTest.java:61:17: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedField +WarnSerializableLambdaTest.java:62:17: compiler.warn.access.to.sensitive.member.from.serializable.element: privateField +WarnSerializableLambdaTest.java:64:43: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:65:43: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:66:43: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:68:17: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:69:17: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:70:17: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:72:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicStaticField +WarnSerializableLambdaTest.java:73:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicClassMethod() +WarnSerializableLambdaTest.java:76:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceField +WarnSerializableLambdaTest.java:77:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceMethod() +WarnSerializableLambdaTest.java:141:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPackageField +WarnSerializableLambdaTest.java:142:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticProtectedField +WarnSerializableLambdaTest.java:143:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPrivateField +WarnSerializableLambdaTest.java:148:21: compiler.warn.access.to.sensitive.member.from.serializable.element: packageField +WarnSerializableLambdaTest.java:149:21: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedField +WarnSerializableLambdaTest.java:150:21: compiler.warn.access.to.sensitive.member.from.serializable.element: privateField +WarnSerializableLambdaTest.java:152:43: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:153:43: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:154:43: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String) +WarnSerializableLambdaTest.java:156:21: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:157:21: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:158:21: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String) +WarnSerializableLambdaTest.java:160:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicStaticField +WarnSerializableLambdaTest.java:161:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicClassMethod() +WarnSerializableLambdaTest.java:164:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceField +WarnSerializableLambdaTest.java:165:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceMethod() +- compiler.err.warnings.and.werror +1 error +54 warnings
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8029102/WarnSerializableLambdaTestb.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,56 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8029102 + * @summary Enhance compiler warnings for Lambda + * Checks that the warning for accessing non public members of a class is + * fired correctly. + * @compile/fail/ref=WarnSerializableLambdaTestb.out -XDrawDiagnostics -Werror -XDwarnOnAccessToSensitiveMembers WarnSerializableLambdaTestb.java + */ + +import java.io.Serializable; + +public class WarnSerializableLambdaTestb { + public void foo(Secret1 secret) { + Object o = (Runnable & java.io.Serializable) () -> { secret.test(); }; + } + + public void bar(Secret2 secret) { + Object o = (Runnable & java.io.Serializable) () -> { secret.test(); }; + } + + private class Secret1 { + public void test() {} + } + + static private class Secret2 { + public void test() {} + } + + class TestInner { + private int j = 0; + void m() { + Serializable s = new Serializable() { + int i; + void m() { + i = 0; // don't warn + System.out.println(j); //warn + } + }; + } + } + + class TestInner2 { + class W implements Serializable { + public int p = 0; + class I { + public int r = 0; + class K implements Serializable { + void m() { + p = 1; // don't warn owner is serializable + r = 2; // warn owner is not serializable + } + } + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8029102/WarnSerializableLambdaTestb.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,7 @@ +WarnSerializableLambdaTestb.java:14:69: compiler.warn.access.to.sensitive.member.from.serializable.element: test() +WarnSerializableLambdaTestb.java:18:69: compiler.warn.access.to.sensitive.member.from.serializable.element: test() +WarnSerializableLambdaTestb.java:36:40: compiler.warn.access.to.sensitive.member.from.serializable.element: j +WarnSerializableLambdaTestb.java:50:25: compiler.warn.access.to.sensitive.member.from.serializable.element: r +- compiler.err.warnings.and.werror +1 error +4 warnings
--- a/test/tools/javac/T8029569/VarargsAmbiguityCrashTest.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/T8029569/VarargsAmbiguityCrashTest.java Thu May 29 13:46:36 2014 -0700 @@ -1,30 +1,8 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 8029569 + * @test /nodynamiccopyright/ + * @bug 8029569 8037379 * @summary internal javac cast exception when resolving varargs ambiguity + * fix for JDK-8029569 doesn't cover all possible cases * @compile/fail/ref=VarargsAmbiguityCrashTest.out -XDrawDiagnostics VarargsAmbiguityCrashTest.java */
--- a/test/tools/javac/T8029569/VarargsAmbiguityCrashTest.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/T8029569/VarargsAmbiguityCrashTest.out Thu May 29 13:46:36 2014 -0700 @@ -1,2 +1,2 @@ -VarargsAmbiguityCrashTest.java:33:9: compiler.err.ref.ambiguous: m2, kindname.method, m2(java.lang.Exception...), VarargsAmbiguityCrashTest, kindname.method, m2(java.lang.Long,java.lang.Exception...), VarargsAmbiguityCrashTest +VarargsAmbiguityCrashTest.java:11:9: compiler.err.ref.ambiguous: m2, kindname.method, m2(java.lang.Exception...), VarargsAmbiguityCrashTest, kindname.method, m2(java.lang.Long,java.lang.Exception...), VarargsAmbiguityCrashTest 1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8030816/CrashLambdaExpressionWithNonAccessibleIdTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,22 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8030816 + * @summary javac can't compile program with lambda expression + * @compile/fail/ref=CrashLambdaExpressionWithNonAccessibleIdTest.out -XDrawDiagnostics CrashLambdaExpressionWithNonAccessibleIdTest.java + */ + +/* This test must make sure that javac won't crash when compiling lambda + * containing an anonymous innerclass based on an unresolvable type. + */ +public class CrashLambdaExpressionWithNonAccessibleIdTest { + void m() { + m1(()-> { + new A(){ + public void m11() {} + }; + }); + + } + + void m1(Runnable r) {} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8030816/CrashLambdaExpressionWithNonAccessibleIdTest.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,3 @@ +CrashLambdaExpressionWithNonAccessibleIdTest.java:15:35: compiler.err.missing.ret.stmt +CrashLambdaExpressionWithNonAccessibleIdTest.java:14:17: compiler.err.cant.resolve.location: kindname.class, A, , , (compiler.misc.location: kindname.class, CrashLambdaExpressionWithNonAccessibleIdTest, null) +2 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/repeatingAnnotations/8029017/TypeUseTarget.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8029017 + * @summary sanity testing of ElementType validation for repeating annotations + * @compile TypeUseTarget.java + */ + +import java.lang.annotation.*; + +public class TypeUseTarget {} + + +// Case 1: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(Case1Container.class) +@interface Case1 {} + +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.TYPE, + ElementType.TYPE_USE, + ElementType.TYPE_PARAMETER, +}) +@interface Case1Container { + Case1[] value(); +} + + +// Case 2: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(Case2Container.class) +@interface Case2 {} + +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.TYPE, + ElementType.TYPE_USE, +}) +@interface Case2Container { + Case2[] value(); +} + + +// Case 3: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(Case3Container.class) +@interface Case3 {} + +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.TYPE, +}) +@interface Case3Container { + Case3[] value(); +} + + +// Case 4: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(Case4Container.class) +@interface Case4 {} + +@Target({ + ElementType.ANNOTATION_TYPE, +}) +@interface Case4Container { + Case4[] value(); +} + + +// Case 5: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(Case5Container.class) +@interface Case5 {} + +@Target({ + ElementType.TYPE, +}) +@interface Case5Container { + Case5[] value(); +} + + +// Case 6: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(Case6Container.class) +@interface Case6 {} + +@Target({ + ElementType.TYPE_PARAMETER, +}) +@interface Case6Container { + Case6[] value(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/repeatingAnnotations/8029017/TypeUseTargetNeg.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,100 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8029017 + * @summary sanity testing of ElementType validation for repeating annotations + * @compile/fail/ref=TypeUseTargetNeg.out -XDrawDiagnostics TypeUseTargetNeg.java + */ + +import java.lang.annotation.*; + +public class TypeUseTargetNeg {} + +// Case 1: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(FooContainer.class) +@interface Foo {} + +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.TYPE, + ElementType.TYPE_USE, + ElementType.TYPE_PARAMETER, + ElementType.FIELD, + +}) +@interface FooContainer { + Foo[] value(); +} + + +// Case 2: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(BarContainer.class) +@interface Bar {} + +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.TYPE, + ElementType.TYPE_USE, + ElementType.METHOD, +}) +@interface BarContainer { + Bar[] value(); +} + + +// Case 3: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(BazContainer.class) +@interface Baz {} + +@Target({ + ElementType.ANNOTATION_TYPE, + ElementType.TYPE, + ElementType.PARAMETER, +}) +@interface BazContainer { + Baz[] value(); +} + + +// Case 4: +@Target({ + ElementType.TYPE_USE, +}) +@Repeatable(QuxContainer.class) +@interface Qux {} + +@interface QuxContainer { + Qux[] value(); +} + + +// Case 5: +@Target({}) +@Repeatable(QuuxContainer.class) +@interface Quux {} + +@Target({ + ElementType.TYPE_PARAMETER, +}) +@interface QuuxContainer { + Quux[] value(); +} + +// Case 6: +@Repeatable(QuuuxContainer.class) +@interface Quuux {} + +@Target({ + ElementType.TYPE_USE, +}) +@interface QuuuxContainer { + Quuux[] value(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/repeatingAnnotations/8029017/TypeUseTargetNeg.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,7 @@ +TypeUseTargetNeg.java:16:1: compiler.err.invalid.repeatable.annotation.incompatible.target: FooContainer, Foo +TypeUseTargetNeg.java:36:1: compiler.err.invalid.repeatable.annotation.incompatible.target: BarContainer, Bar +TypeUseTargetNeg.java:54:1: compiler.err.invalid.repeatable.annotation.incompatible.target: BazContainer, Baz +TypeUseTargetNeg.java:71:1: compiler.err.invalid.repeatable.annotation.incompatible.target: QuxContainer, Qux +TypeUseTargetNeg.java:81:1: compiler.err.invalid.repeatable.annotation.incompatible.target: QuuxContainer, Quux +TypeUseTargetNeg.java:92:1: compiler.err.invalid.repeatable.annotation.incompatible.target: QuuuxContainer, Quuux +6 errors
--- a/test/tools/javac/annotations/repeatingAnnotations/combo/ReflectionTest.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/annotations/repeatingAnnotations/combo/ReflectionTest.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /** * @test - * @bug 8001457 + * @bug 8001457 8027477 * @author sogoel * @summary Reflection api tests * @build Helper @@ -159,7 +159,12 @@ "SingleOnSuperContainerAndSingleOnSub_Inherited_Legacy", "ContainerAndSingleOnSuperSingleOnSub_Inherited_Legacy", "SingleAnnoWithContainer", - "SingleOnSuperContainerAndSingleOnSub_Inherited"); + "SingleOnSuperContainerAndSingleOnSub_Inherited", + "RepeatableOnSuperSingleOnSub_Inherited", + "SingleOnSuperRepeatableOnSub_Inherited", + "ContainerOnSuperSingleOnSub_Inherited", + "SingleOnSuperContainerOnSub_Inherited", + "ContainerAndSingleOnSuperSingleOnSub_Inherited"); if (orderingTestFailures.contains(testCase.toString())) { CHECKORDERING = false; } else @@ -1612,323 +1617,323 @@ return files; } }, -// // Testcase not working as expected, JDK-8004912 -// RepeatableOnSuperSingleOnSub_Inherited( -// "@ExpectedBase(value=Foo.class, " -// + "getAnnotationVal = \"Foo\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + //override every annotation on superClass -// "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, " -// + // ignores inherited annotations -// "getDeclAnnoVal = \"Foo\", " // ignores inherited -// + "getAnnosArgs = {\"Foo\"}, " -// + "getDeclAnnosArgs = { \"Foo\" })", // ignores inherited -// "@ExpectedContainer(value=FooContainer.class, " -// + "getAnnotationVal = \"FooContainer\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, " -// + // ignores inherited annotations -// "getDeclAnnoVal = \"NULL\", " -// + "getAnnosArgs = {\"FooContainer\"}, " -// + "getDeclAnnosArgs = {}) // ignores inherited ") { + // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest + // fail with ordering issues + RepeatableOnSuperSingleOnSub_Inherited( + "@ExpectedBase(value=Foo.class, " + + "getAnnotationVal = \"@Foo(value=3)\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=3)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + //override every annotation on superClass + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=3)\"}, " + + // ignores inherited annotations + "getDeclAnnoVal = \"@Foo(value=3)\", " // ignores inherited + + "getAnnosArgs = {\"@Foo(value=3)\"}, " + + "getDeclAnnosArgs = { \"@Foo(value=3)\" })", // ignores inherited + "@ExpectedContainer(value=FooContainer.class, " + + "getAnnotationVal = \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=3)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=3)\"}, " + + // ignores inherited annotations + "getDeclAnnoVal = \"NULL\", " + + "getAnnosArgs = {\"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosArgs = {}) // ignores inherited ") { -// @Override -// public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, -// String className) { -// String anno = ""; -// String replaceVal = ""; -// String contents = ""; -// JavaFileObject srcFileObj = null; -// Iterable<? extends JavaFileObject> files = null; + @Override + public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, + String className) { + String anno = ""; + String replaceVal = ""; + String contents = ""; + JavaFileObject srcFileObj = null; + Iterable<? extends JavaFileObject> files = null; -// String expectedVals = "\n" + getExpectedBase() + "\n" -// + getExpectedContainer() + "\n"; -// StringBuilder commonStmts = getCommonStmts(true); + String expectedVals = "\n" + getExpectedBase() + "\n" + + getExpectedContainer() + "\n"; + StringBuilder commonStmts = getCommonStmts(true); -// /* -// Sample testSrc: -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @Repeatable(FooContainer.class) -// @interface Foo {int value() default Integer.MAX_VALUE;} + /* + Sample testSrc: + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @Repeatable(FooContainer.class) + @interface Foo {int value() default Integer.MAX_VALUE;} -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @interface FooContainer { -// Foo[] value(); -// } + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @interface FooContainer { + Foo[] value(); + } -// @Foo() @Foo -// class SuperClass { } + @Foo(1) @Foo(2) + class SuperClass { } -// @ExpectedBase -// @ExpectedContainer -// @Foo -// class SubClass extends SuperClass { } -// */ -// //@Inherited only works for classes, no switch cases for method, field, package - -// if (srcType == SrcType.CLASS) { -// //Contents for SuperClass -// anno = Helper.ContentVars.REPEATABLEANNO.getVal(); -// replaceVal = commonStmts + "\n" + anno; -// String superClassContents = srcType.getTemplate() -// .replace("#CN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); + @ExpectedBase + @ExpectedContainer + @Foo(3) + class SubClass extends SuperClass { } + */ + //@Inherited only works for classes, no switch cases for method, field, package + if (srcType == SrcType.CLASS) { + //Contents for SuperClass + anno = Helper.ContentVars.REPEATABLEANNO.getVal(); + replaceVal = commonStmts + "\n" + anno; + String superClassContents = srcType.getTemplate() + .replace("#CN", SUPERCLASS) + .replace("#REPLACE", replaceVal); -// //Contents for SubClass that extends SuperClass -// anno = "@Foo(0)"; -// replaceVal = expectedVals + "\n" + anno; -// String subClassContents = SrcType.CLASSEXTENDS.getTemplate() -// .replace("#CN", className) -// .replace("#SN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); -// contents = superClassContents + subClassContents; -// srcFileObj = Helper.getFile(className, contents); -// files = Arrays.asList(srcFileObj); -// } -// return files; -// } -// }, -// //Testcase not working as expected, JDK-8004912 -// SingleOnSuperRepeatableOnSub_Inherited( -// "@ExpectedBase(value=Foo.class, " -// + "getAnnotationVal = \"Foo\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + //override every annotation on superClass -// "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, " -// + // ignores inherited annotations -// "getDeclAnnoVal = \"NULL\","// ignores inherited -// + "getAnnosArgs = {\"Foo\", \"Foo\"}, " -// + "getDeclAnnosArgs = { \"Foo\", \"Foo\"})", -// "@ExpectedContainer(value=FooContainer.class, " -// + "getAnnotationVal = \"FooContainer\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, " -// + // ignores inherited annotations -// "getDeclAnnoVal = \"FooContainer\", "// ignores inherited -// + "getAnnosArgs = {\"FooContainer\"}, " -// + "getDeclAnnosArgs = {\"FooContainer\"})") { + //Contents for SubClass that extends SuperClass + anno = "@Foo(3)"; + replaceVal = expectedVals + "\n" + anno; + String subClassContents = SrcType.CLASSEXTENDS.getTemplate() + .replace("#CN", className) + .replace("#SN", SUPERCLASS) + .replace("#REPLACE", replaceVal); + contents = superClassContents + subClassContents; + srcFileObj = Helper.getFile(className, contents); + files = Arrays.asList(srcFileObj); + } + return files; + } + }, + // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest + // fail with ordering issues + SingleOnSuperRepeatableOnSub_Inherited( + "@ExpectedBase(value=Foo.class, " + + "getAnnotationVal = \"@Foo(value=0)\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + //override every annotation on superClass + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + // ignores inherited annotations + "getDeclAnnoVal = \"NULL\","// ignores inherited + + "getAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"}, " + + "getDeclAnnosArgs = { \"@Foo(value=1)\", \"@Foo(value=2)\"})", + "@ExpectedContainer(value=FooContainer.class, " + + "getAnnotationVal = \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + // ignores inherited annotations + "getDeclAnnoVal = \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\", "// ignores inherited + + "getAnnosArgs = {\"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosArgs = {\"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"})") { -// @Override -// public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, -// String className) { -// String anno = ""; -// String replaceVal = ""; -// String contents = ""; -// JavaFileObject srcFileObj = null; -// Iterable<? extends JavaFileObject> files = null; - -// String expectedVals = "\n" + getExpectedBase() + "\n" -// + getExpectedContainer() + "\n"; -// StringBuilder commonStmts = getCommonStmts(true); + @Override + public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, + String className) { + String anno = ""; + String replaceVal = ""; + String contents = ""; + JavaFileObject srcFileObj = null; + Iterable<? extends JavaFileObject> files = null; -// /* -// Sample testSrc: -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @Repeatable(FooContainer.class) -// @interface Foo {int value() default Integer.MAX_VALUE;} + String expectedVals = "\n" + getExpectedBase() + "\n" + + getExpectedContainer() + "\n"; + StringBuilder commonStmts = getCommonStmts(true); -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @interface FooContainer { -// Foo[] value(); -// } + /* + Sample testSrc: + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @Repeatable(FooContainer.class) + @interface Foo {int value() default Integer.MAX_VALUE;} -// @Foo() -// class SuperClass { } + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @interface FooContainer { + Foo[] value(); + } -// @ExpectedBase -// @ExpectedContainer -// @Foo @Foo -// class SubClass extends SuperClass { } -// */ + @Foo(0) + class SuperClass { } -// //@Inherited only works for classes, no switch cases for method, field, package -// if (srcType == SrcType.CLASS) { -// //Contents for SuperClass -// anno = "@Foo(0)"; -// replaceVal = commonStmts + "\n" + anno; -// String superClassContents = srcType.getTemplate() -// .replace("#CN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); + @ExpectedBase + @ExpectedContainer + @Foo(1) @Foo(2) + class SubClass extends SuperClass { } + */ + //@Inherited only works for classes, no switch cases for method, field, package + if (srcType == SrcType.CLASS) { + //Contents for SuperClass + anno = Helper.ContentVars.BASEANNO.getVal(); + replaceVal = commonStmts + "\n" + anno; + String superClassContents = srcType.getTemplate() + .replace("#CN", SUPERCLASS) + .replace("#REPLACE", replaceVal); -// //Contents for SubClass that extends SuperClass -// anno = Helper.ContentVars.REPEATABLEANNO.getVal(); -// replaceVal = expectedVals + "\n" + anno; -// String subClassContents = SrcType.CLASSEXTENDS.getTemplate() -// .replace("#CN", className) -// .replace("#SN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); + //Contents for SubClass that extends SuperClass + anno = Helper.ContentVars.REPEATABLEANNO.getVal(); + replaceVal = expectedVals + "\n" + anno; + String subClassContents = SrcType.CLASSEXTENDS.getTemplate() + .replace("#CN", className) + .replace("#SN", SUPERCLASS) + .replace("#REPLACE", replaceVal); -// contents = superClassContents + subClassContents; -// srcFileObj = Helper.getFile(className, contents); -// files = Arrays.asList(srcFileObj); -// } -// return files; -// } -// }, -// //Testcase not working as expected, JDK-8004912 -// ContainerOnSuperSingleOnSub_Inherited( -// "@ExpectedBase(value=Foo.class, " -// + "getAnnotationVal = \"Foo\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}," -// + "getDeclAnnoVal = \"Foo\"," -// + "getAnnosArgs = {\"Foo\"}," -// + "getDeclAnnosArgs = {\"Foo\"})", -// "@ExpectedContainer(value=FooContainer.class, " -// + "getAnnotationVal = \"FooContainer\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}," -// + "getDeclAnnoVal = \"NULL\"," -// + "getAnnosArgs = {\"FooContainer\"}," -// + "getDeclAnnosArgs = {})") { + contents = superClassContents + subClassContents; + srcFileObj = Helper.getFile(className, contents); + files = Arrays.asList(srcFileObj); + } + return files; + } + }, + // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest + // fail with ordering issues + ContainerOnSuperSingleOnSub_Inherited( + "@ExpectedBase(value=Foo.class, " + + "getAnnotationVal = \"@Foo(value=0)\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"}," + + "getDeclAnnoVal = \"@Foo(value=0)\"," + + "getAnnosArgs = {\"@Foo(value=0)\"}," + + "getDeclAnnosArgs = {\"@Foo(value=0)\"})", + "@ExpectedContainer(value=FooContainer.class, " + + "getAnnotationVal = \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"}," + + "getDeclAnnoVal = \"NULL\"," + + "getAnnosArgs = {\"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}," + + "getDeclAnnosArgs = {})") { -// @Override -// public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, -// String className) { -// String anno = ""; -// String replaceVal = ""; -// String contents = ""; -// JavaFileObject srcFileObj = null; -// Iterable<? extends JavaFileObject> files = null; - -// String expectedVals = "\n" + getExpectedBase() + "\n" -// + getExpectedContainer() + "\n"; -// StringBuilder commonStmts = getCommonStmts(true); + @Override + public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, + String className) { + String anno = ""; + String replaceVal = ""; + String contents = ""; + JavaFileObject srcFileObj = null; + Iterable<? extends JavaFileObject> files = null; -// /* -// Sample testSrc: -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @Repeatable(FooContainer.class) -// @interface Foo {int value() default Integer.MAX_VALUE;} + String expectedVals = "\n" + getExpectedBase() + "\n" + + getExpectedContainer() + "\n"; + StringBuilder commonStmts = getCommonStmts(true); -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @interface FooContainer { -// Foo[] value(); -// } + /* + Sample testSrc: + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @Repeatable(FooContainer.class) + @interface Foo {int value() default Integer.MAX_VALUE;} -// @FooContainer(value = {@Foo, @Foo}) -// class SuperClass { } + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @interface FooContainer { + Foo[] value(); + } + + @FooContainer(value = {@Foo(1), @Foo(2)}) + class SuperClass { } -// @ExpectedBase -// @ExpectedContainer -// @Foo -// class SubClass extends SuperClass { } -// */ + @ExpectedBase + @ExpectedContainer + @Foo(0) + class SubClass extends SuperClass { } + */ + //@Inherited only works for classes, no switch cases for method, field, package + if (srcType == SrcType.CLASS) { + //Contents for SuperClass + anno = Helper.ContentVars.LEGACYCONTAINER.getVal(); + replaceVal = commonStmts + "\n" + anno; + String superClassContents = srcType.getTemplate() + .replace("#CN", SUPERCLASS) + .replace("#REPLACE", replaceVal); -// //@Inherited only works for classes, no switch cases for method, field, package -// if (srcType == SrcType.CLASS) { -// //Contents for SuperClass -// anno = Helper.ContentVars.LEGACYCONTAINER.getVal(); -// replaceVal = commonStmts + "\n" + anno; -// String superClassContents = srcType.getTemplate() -// .replace("#CN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); - -// //Contents for SubClass that extends SuperClass -// anno = "@Foo(0)"; -// replaceVal = expectedVals + "\n" + anno; -// String subClassContents = SrcType.CLASSEXTENDS.getTemplate() -// .replace("#CN", className) -// .replace("#SN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); + //Contents for SubClass that extends SuperClass + anno = Helper.ContentVars.BASEANNO.getVal(); + replaceVal = expectedVals + "\n" + anno; + String subClassContents = SrcType.CLASSEXTENDS.getTemplate() + .replace("#CN", className) + .replace("#SN", SUPERCLASS) + .replace("#REPLACE", replaceVal); -// contents = superClassContents + subClassContents; -// srcFileObj = Helper.getFile(className, contents); -// files = Arrays.asList(srcFileObj); -// } -// return files; -// } -// }, -// // TestCase not working as expected, JDK-8004912 -// SingleOnSuperContainerOnSub_Inherited( -// "@ExpectedBase(value=Foo.class, " -// + "getAnnotationVal = \"Foo\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}," -// + "getDeclAnnoVal = \"NULL\"," -// + "getAnnosArgs = {\"Foo\", \"Foo\"}," -// + "getDeclAnnosArgs = {\"Foo\", \"Foo\"})", -// "@ExpectedContainer(value=FooContainer.class, " -// + "getAnnotationVal = \"FooContainer\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}," -// + "getDeclAnnoVal = \"FooContainer\"," -// + "getAnnosArgs = {\"FooContainer\"}," -// + "getDeclAnnosArgs = {\"FooContainer\"})") { + contents = superClassContents + subClassContents; + srcFileObj = Helper.getFile(className, contents); + files = Arrays.asList(srcFileObj); + } + return files; + } + }, + // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest + // fail with ordering issues + SingleOnSuperContainerOnSub_Inherited( + "@ExpectedBase(value=Foo.class, " + + "getAnnotationVal = \"@Foo(value=0)\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}," + + "getDeclAnnoVal = \"NULL\"," + + "getAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"}," + + "getDeclAnnosArgs = {\"@Foo(value=1)\", \"@Foo(value=2)\"})", + "@ExpectedContainer(value=FooContainer.class, " + + "getAnnotationVal = \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}," + + "getDeclAnnoVal = \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"," + + "getAnnosArgs = {\"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}," + + "getDeclAnnosArgs = {\"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"})") { -// @Override -// public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, -// String className) { -// String anno = ""; -// String replaceVal = ""; -// String contents = ""; -// JavaFileObject srcFileObj = null; -// Iterable<? extends JavaFileObject> files = null; + @Override + public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, + String className) { + String anno = ""; + String replaceVal = ""; + String contents = ""; + JavaFileObject srcFileObj = null; + Iterable<? extends JavaFileObject> files = null; -// String expectedVals = "\n" + getExpectedBase() + "\n" -// + getExpectedContainer() + "\n"; -// StringBuilder commonStmts = getCommonStmts(true); + String expectedVals = "\n" + getExpectedBase() + "\n" + + getExpectedContainer() + "\n"; + StringBuilder commonStmts = getCommonStmts(true); -// /* -// Sample testSrc: -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @Repeatable(FooContainer.class) -// @interface Foo {int value() default Integer.MAX_VALUE;} + /* + Sample testSrc: + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @Repeatable(FooContainer.class) + @interface Foo {int value() default Integer.MAX_VALUE;} -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @interface FooContainer { -// Foo[] value(); -// } + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @interface FooContainer { + Foo[] value(); + } -// @Foo -// class SuperClass { } - -// @ExpectedBase -// @ExpectedContainer -// @FooContainer(value = {@Foo, @Foo}) -// class SubClass extends SuperClass { } -// */ + @Foo(0) + class SuperClass { } -// //@Inherited only works for classes, no switch cases for method, field, package -// if (srcType == SrcType.CLASS) { -// //Contents for SuperClass -// anno = "@Foo(0)"; -// replaceVal = commonStmts + "\n" + anno; -// String superClassContents = srcType.getTemplate() -// .replace("#CN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); + @ExpectedBase + @ExpectedContainer + @FooContainer(value = {@Foo(1), @Foo(2)}) + class SubClass extends SuperClass { } + */ + //@Inherited only works for classes, no switch cases for method, field, package + if (srcType == SrcType.CLASS) { + //Contents for SuperClass + anno = Helper.ContentVars.BASEANNO.getVal(); + replaceVal = commonStmts + "\n" + anno; + String superClassContents = srcType.getTemplate() + .replace("#CN", SUPERCLASS) + .replace("#REPLACE", replaceVal); -// //Contents for SubClass that extends SuperClass -// anno = Helper.ContentVars.LEGACYCONTAINER.getVal(); -// replaceVal = expectedVals + "\n" + anno; -// String subClassContents = SrcType.CLASSEXTENDS.getTemplate() -// .replace("#CN", className) -// .replace("#SN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); + //Contents for SubClass that extends SuperClass + anno = Helper.ContentVars.LEGACYCONTAINER.getVal(); + replaceVal = expectedVals + "\n" + anno; + String subClassContents = SrcType.CLASSEXTENDS.getTemplate() + .replace("#CN", className) + .replace("#SN", SUPERCLASS) + .replace("#REPLACE", replaceVal); -// contents = superClassContents + subClassContents; -// srcFileObj = Helper.getFile(className, contents); -// files = Arrays.asList(srcFileObj); -// } -// return files; -// } -// }, + contents = superClassContents + subClassContents; + srcFileObj = Helper.getFile(className, contents); + files = Arrays.asList(srcFileObj); + } + return files; + } + }, // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest // fail with ordering issues SingleOnSuperContainerAndSingleOnSub_Inherited( @@ -2009,87 +2014,88 @@ return files; } }, -// // TestCase not working as expected, JDK-8004912 -// ContainerAndSingleOnSuperSingleOnSub_Inherited( -// "@ExpectedBase(value=Foo.class, " -// + "getAnnotationVal = \"Foo\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}," -// + "getDeclAnnoVal = \"Foo\"," -// + "getAnnosArgs = {\"Foo\"}," -// + "getDeclAnnosArgs = {\"Foo\"})", -// "@ExpectedContainer(value=FooContainer.class, " -// + "getAnnotationVal = \"FooContainer\", " -// + "getAnnotationsVals = {" -// + "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, " -// + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}," -// + "getDeclAnnoVal = \"NULL\"," -// + "getAnnosArgs = {\"FooContainer\"}," -// + "getDeclAnnosArgs = {})") { + // @ignore 8025924: Several test cases in repeatingAnnotations/combo/ReflectionTest + // fail with ordering issues + ContainerAndSingleOnSuperSingleOnSub_Inherited( + "@ExpectedBase(value=Foo.class, " + + "getAnnotationVal = \"@Foo(value=0)\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"}," + + "getDeclAnnoVal = \"@Foo(value=0)\"," + + "getAnnosArgs = {\"@Foo(value=0)\"}," + + "getDeclAnnosArgs = {\"@Foo(value=0)\"})", + "@ExpectedContainer(value=FooContainer.class, " + + "getAnnotationVal = \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\", " + + "getAnnotationsVals = {" + + "\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\", \"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}, " + + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"@Foo(value=0)\"}," + + "getDeclAnnoVal = \"NULL\"," + + "getAnnosArgs = {\"@FooContainer(value=[@Foo(value=1), @Foo(value=2)])\"}," + + "getDeclAnnosArgs = {})") { -// @Override -// public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, -// String className) { -// String anno = ""; -// String replaceVal = ""; -// String contents = ""; -// JavaFileObject srcFileObj = null; -// Iterable<? extends JavaFileObject> files = null; + @Override + public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType, + String className) { + String anno = ""; + String replaceVal = ""; + String contents = ""; + JavaFileObject srcFileObj = null; + Iterable<? extends JavaFileObject> files = null; -// String expectedVals = "\n" + getExpectedBase() + "\n" -// + getExpectedContainer() + "\n"; -// StringBuilder commonStmts = getCommonStmts(true); + String expectedVals = "\n" + getExpectedBase() + "\n" + + getExpectedContainer() + "\n"; + StringBuilder commonStmts = getCommonStmts(true); -// /* -// Sample testSrc: -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @Repeatable(FooContainer.class) -// @interface Foo {int value() default Integer.MAX_VALUE;} + /* + Sample testSrc: + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @Repeatable(FooContainer.class) + @interface Foo {int value() default Integer.MAX_VALUE;} -// @Retention(RetentionPolicy.RUNTIME) -// @Inherited -// @interface FooContainer { -// Foo[] value(); -// } + @Retention(RetentionPolicy.RUNTIME) + @Inherited + @interface FooContainer { + Foo[] value(); + } -// @FooContainer(value = {@Foo, @Foo}) -// @Foo -// class SuperClass { } + @FooContainer(value = {@Foo(1), @Foo(2)}) + @Foo(3) + class SuperClass { } -// @ExpectedBase -// @ExpectedContainer -// @Foo -// class SubClass extends SuperClass { } -// */ + @ExpectedBase + @ExpectedContainer + @Foo(0) + class SubClass extends SuperClass { } + */ -// //@Inherited only works for classes, no switch cases for method, field, package -// if (srcType == SrcType.CLASS) { -// //Contents for SuperClass -// anno = Helper.ContentVars.LEGACYCONTAINER.getVal() -// + Helper.ContentVars.BASEANNO.getVal(); -// replaceVal = commonStmts + "\n" + anno; -// String superClassContents = srcType.getTemplate() -// .replace("#CN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); + //@Inherited only works for classes, no switch cases for method, field, package + if (srcType == SrcType.CLASS) { + //Contents for SuperClass + anno = Helper.ContentVars.LEGACYCONTAINER.getVal() + + "@Foo(3)" ; + replaceVal = commonStmts + "\n" + anno; + String superClassContents = srcType.getTemplate() + .replace("#CN", SUPERCLASS) + .replace("#REPLACE", replaceVal); -// //Contents for SubClass that extends SuperClass -// anno = "@Foo(0)"; -// replaceVal = expectedVals + "\n" + anno; -// String subClassContents = SrcType.CLASSEXTENDS.getTemplate() -// .replace("#CN", className) -// .replace("#SN", SUPERCLASS) -// .replace("#REPLACE", replaceVal); + //Contents for SubClass that extends SuperClass + anno = Helper.ContentVars.BASEANNO.getVal(); + replaceVal = expectedVals + "\n" + anno; + String subClassContents = SrcType.CLASSEXTENDS.getTemplate() + .replace("#CN", className) + .replace("#SN", SUPERCLASS) + .replace("#REPLACE", replaceVal); -// contents = superClassContents + subClassContents; -// srcFileObj = Helper.getFile(className, contents); -// files = Arrays.asList(srcFileObj); -// } -// return files; -// } -// } - ; + contents = superClassContents + subClassContents; + srcFileObj = Helper.getFile(className, contents); + files = Arrays.asList(srcFileObj); + } + return files; + } + }; + private String expectedBase, expectedContainer; private TestCase(String expectedBase, String expectedContainer) { @@ -2942,7 +2948,7 @@ System.out.print("Actual Arr Values: "); for (Annotation a : actualAnnos) { if (a != null && a.annotationType() != null) { - System.out.print("[" + a.annotationType().getSimpleName() + "]"); + System.out.print("[" + a.toString() + "]"); } else { System.out.println("[null]"); }
--- a/test/tools/javac/annotations/repeatingAnnotations/combo/TargetAnnoCombo.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/annotations/repeatingAnnotations/combo/TargetAnnoCombo.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 7151010 8006547 8007766 + * @bug 7151010 8006547 8007766 8029017 * @summary Default test cases for running combinations for Target values * @build Helper * @run main TargetAnnoCombo @@ -145,11 +145,19 @@ Set<ElementType> tempBaseSet = EnumSet.noneOf(ElementType.class); tempBaseSet.addAll(baseAnnotations); + // If BaseAnno has TYPE, then ANNOTATION_TYPE is allowed by default. if (baseAnnotations.contains(TYPE)) { tempBaseSet.add(ANNOTATION_TYPE); } + // If BaseAnno has TYPE_USE, then add the extra allowed types + if (baseAnnotations.contains(TYPE_USE)) { + tempBaseSet.add(ANNOTATION_TYPE); + tempBaseSet.add(TYPE); + tempBaseSet.add(TYPE_PARAMETER); + } + // If containerAnno has no @Target, only valid case if baseAnnoTarget has // all targets defined else invalid set. if (containerAnnotations == null) {
--- a/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out Thu May 29 13:46:36 2014 -0700 @@ -6,6 +6,7 @@ CantAnnotateScoping.java:56:37: compiler.err.cant.type.annotate.scoping: @TA,@TA2 CantAnnotateScoping.java:40:14: compiler.err.cant.type.annotate.scoping.1: @TA CantAnnotateScoping.java:42:34: compiler.err.cant.type.annotate.scoping: @TA,@DA,@TA2 +CantAnnotateScoping.java:42:25: compiler.err.annotation.type.not.applicable CantAnnotateScoping.java:44:38: compiler.err.cant.type.annotate.scoping: @TA,@DA CantAnnotateScoping.java:44:34: compiler.err.annotation.type.not.applicable -10 errors \ No newline at end of file +11 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/typeAnnotations/failures/CheckErrorsForSource7.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/**@test + * @bug 8035890 + * @summary Verify that the parser correctly checks for source level 8 on the new places where + * annotations can appear in 8. + * @run main CheckErrorsForSource7 CheckErrorsForSource7.java + */ +import java.io.File; +import java.io.IOException; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.tools.Diagnostic; +import javax.tools.DiagnosticCollector; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.IdentifierTree; +import com.sun.source.tree.Tree.Kind; +import com.sun.source.util.JavacTask; +import com.sun.source.util.TreePathScanner; +import com.sun.source.util.Trees; +import com.sun.tools.javac.api.JavacTool; +import com.sun.tools.javac.file.JavacFileManager; + +/**For each place where an annotation can syntactically appear with -source 8, but not with + * -source 7, this test verifies that an error is correctly emitted from the parser for + * the annotation for -source 7. This test first gathers the occurrences of @TA from + * the CheckErrorsForSource7Data class below, and then repeatedly removes all these annotations + * except one and checks the parser reports an expected error. This is needed as as the parser + * typically produces only one 'insufficient source level' error for each new feature used. + */ +public class CheckErrorsForSource7 { + public static void main(String... args) throws IOException, URISyntaxException { + new CheckErrorsForSource7().run(args); + } + + private void run(String... args) throws IOException, URISyntaxException { + //the first and only parameter must be the name of the file to be analyzed: + if (args.length != 1) throw new IllegalStateException("Must provide source file!"); + File testSrc = new File(System.getProperty("test.src")); + File testFile = new File(testSrc, args[0]); + if (!testFile.canRead()) throw new IllegalStateException("Cannot read the test source"); + JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); + + //gather spans of the @TA annotations into typeAnnotationSpans: + JavacTask task = JavacTool.create().getTask(null, + fm, + null, + Collections.<String>emptyList(), + null, + fm.getJavaFileObjects(testFile)); + final Trees trees = Trees.instance(task); + final CompilationUnitTree cut = task.parse().iterator().next(); + final List<int[]> typeAnnotationSpans = new ArrayList<>(); + + new TreePathScanner<Void, Void>() { + @Override + public Void visitAnnotation(AnnotationTree node, Void p) { + if (node.getAnnotationType().getKind() == Kind.IDENTIFIER && + ((IdentifierTree) node.getAnnotationType()).getName().contentEquals("TA")) { + int start = (int) trees.getSourcePositions().getStartPosition(cut, node); + int end = (int) trees.getSourcePositions().getEndPosition(cut, node); + typeAnnotationSpans.add(new int[] {start, end}); + } + return null; + } + }.scan(cut, null); + + //sort the spans in the reverse order, to simplify removing them from the source: + Collections.sort(typeAnnotationSpans, new Comparator<int[]>() { + @Override + public int compare(int[] o1, int[] o2) { + return o2[0] - o1[0]; + } + }); + + //verify the errors are produce correctly: + String originalSource = cut.getSourceFile().getCharContent(false).toString(); + + for (int[] toKeep : typeAnnotationSpans) { + //prepare updated source code by removing all the annotations except the toKeep one: + String updated = originalSource; + + for (int[] span : typeAnnotationSpans) { + if (span == toKeep) continue; + + updated = updated.substring(0, span[0]) + updated.substring(span[1]); + } + + //parse and verify: + JavaFileObject updatedFile = new TestFO(cut.getSourceFile().toUri(), updated); + DiagnosticCollector<JavaFileObject> errors = new DiagnosticCollector<>(); + JavacTask task2 = JavacTool.create().getTask(null, + fm, + errors, + Arrays.asList("-source", "7"), + null, + Arrays.asList(updatedFile)); + task2.parse(); + + boolean found = false; + + for (Diagnostic<? extends JavaFileObject> d : errors.getDiagnostics()) { + if (d.getKind() == Diagnostic.Kind.ERROR && EXPECTED_ERRORS.contains(d.getCode())) { + if (found) { + throw new IllegalStateException("More than one expected error found."); + } + found = true; + } + } + + if (!found) + throw new IllegalStateException("Did not produce proper errors for: " + updated); + } + } + + static final Set<String> EXPECTED_ERRORS = new HashSet<>(Arrays.asList( + "compiler.err.type.annotations.not.supported.in.source", + "compiler.err.annotations.after.type.params.not.supported.in.source" + )); + + class TestFO extends SimpleJavaFileObject { + private final String content; + public TestFO(URI uri, String content) { + super(uri, Kind.SOURCE); + this.content = content; + } + + @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + return content; + } + + @Override public boolean isNameCompatible(String simpleName, Kind kind) { + return true; + } + } +} + +//data on which the source level check is verified: +class CheckErrorsForSource7Data { + @Target(ElementType.TYPE_USE) + @interface TA { } + + Object n1 = new @TA ArrayList<@TA String>(); + Object n2 = new @TA Object() {}; + Object [] @TA [] arr @TA[]; + <T> @TA int @TA[] ret(Object obj) @TA[] throws @TA Exception { + this.<@TA String>ret(null); + Object c1 = new @TA String[1]; + + int val = obj instanceof @TA String ? ((@TA String) obj).length() : 0; + List<@TA ?> l; + return null; + } + void vararg(String @TA ... args) { } + + abstract class C<@TA T extends @TA Number & @TA Runnable> + extends @TA ArrayList<@TA String> + implements java.util. @TA Comparator<@TA T> { } + + interface I extends java.util. @TA Comparator<@TA String> { } + +}
--- a/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ +DeclarationAnnotation.java:13:21: compiler.err.annotation.type.not.applicable DeclarationAnnotation.java:10:21: compiler.err.annotation.type.not.applicable DeclarationAnnotation.java:11:21: compiler.err.annotation.type.not.applicable DeclarationAnnotation.java:12:21: compiler.err.annotation.type.not.applicable -DeclarationAnnotation.java:13:21: compiler.err.annotation.type.not.applicable 4 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/AfterMethodTypeParams.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8038788 + * @summary Verify proper handling of annotations after method's type parameters. + * @build AfterMethodTypeParams + * @run main AfterMethodTypeParams + */ + +import java.io.IOException; +import java.io.StringWriter; +import java.net.URI; +import java.util.*; + +import javax.lang.model.element.Name; +import javax.tools.*; + +import com.sun.source.tree.*; +import com.sun.source.util.*; + +public class AfterMethodTypeParams { + + public static void main(String... args) throws IOException { + new AfterMethodTypeParams().run(); + } + + void run() throws IOException { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + + for (TestCase tc : testCases) { + String test = TEMPLATE.replace("CONTENT", tc.snippet); + List<JavaFileObject> files = Arrays.asList(new MyFileObject(test)); + StringWriter out = new StringWriter(); + List<String> options = Arrays.asList("-XDrawDiagnostics", "-XDshouldStopPolicy=FLOW"); + JavacTask task = (JavacTask) compiler.getTask(out, null, null, options, null, files); + + new TreePathScanner<Void, Void>() { + boolean seenAnnotation; + @Override + public Void visitAnnotation(AnnotationTree node, Void p) { + Name name = ((IdentifierTree) node.getAnnotationType()).getName(); + seenAnnotation |= name.contentEquals("TA") || name.contentEquals("DA"); + return null; + } + @Override + public Void visitCompilationUnit(CompilationUnitTree node, Void p) { + super.visitCompilationUnit(node, p); + if (!seenAnnotation) + error(test, "Annotation was missing"); + return null; + } + }.scan(task.parse(), null); + + task.analyze(); + + if (!tc.error.equals(out.toString().trim())) { + error(test, "Incorrect errors: " + out.toString()); + } + } + + if (errors > 0) { + throw new IllegalStateException("Errors found"); + } + } + + int errors; + + void error(String code, String error) { + System.out.println("Error detected: " + error); + System.out.println("Code:"); + System.out.println(code); + errors++; + } + + static String TEMPLATE = + "import java.lang.annotation.*;\n" + + "public class Test {\n" + + " CONTENT\n" + + "}\n" + + "@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})\n" + + "@interface DA { }\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface TA { }\n"; + + static class MyFileObject extends SimpleJavaFileObject { + final String text; + public MyFileObject(String text) { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + this.text = text; + } + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return text; + } + } + + static TestCase[] testCases = new TestCase[] { + new TestCase("<T> @DA int foo1() { return 0;}", ""), + new TestCase("<T> @DA void foo2() { }", ""), + new TestCase("<T> @TA int foo3() { return 0;}", ""), + new TestCase("<T> @TA void foo4() { }", + "Test.java:3:9: compiler.err.annotation.type.not.applicable"), + new TestCase("<T> @DA Test() { }", "Test.java:3:9: compiler.err.illegal.start.of.type"), + new TestCase("<T> @TA Test() { }", "Test.java:3:9: compiler.err.illegal.start.of.type"), + }; + + static class TestCase { + final String snippet; + final String error; + public TestCase(String snippet, String error) { + this.snippet = snippet; + this.error = error; + } + } +} +
--- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/Driver.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,7 @@ import java.lang.annotation.*; import java.lang.reflect.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -51,6 +52,11 @@ new Driver().runDriver(clazz.newInstance()); } + String[][] extraParamsCombinations = new String[][] { + new String[] { }, + new String[] { "-g" }, + }; + protected void runDriver(Object object) throws Exception { int passed = 0, failed = 0; Class<?> clazz = object.getClass(); @@ -65,18 +71,20 @@ throw new IllegalArgumentException("Test method needs to return a string: " + method); String testClass = testClassOf(method); - try { - String compact = (String)method.invoke(object); - String fullFile = wrap(compact); - ClassFile cf = compileAndReturn(fullFile, testClass); - List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf); - ReferenceInfoUtil.compare(expected, actual, cf); - out.println("PASSED: " + method.getName()); - ++passed; - } catch (Throwable e) { - out.println("FAILED: " + method.getName()); - out.println(" " + e.toString()); - ++failed; + for (String[] extraParams : extraParamsCombinations) { + try { + String compact = (String)method.invoke(object); + String fullFile = wrap(compact); + ClassFile cf = compileAndReturn(fullFile, testClass, extraParams); + List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf); + ReferenceInfoUtil.compare(expected, actual, cf); + out.println("PASSED: " + method.getName()); + ++passed; + } catch (Throwable e) { + out.println("FAILED: " + method.getName()); + out.println(" " + e.toString()); + ++failed; + } } } @@ -156,7 +164,7 @@ } } - private ClassFile compileAndReturn(String fullFile, String testClass) throws Exception { + private ClassFile compileAndReturn(String fullFile, String testClass, String... extraParams) throws Exception { File source = writeTestFile(fullFile); File clazzFile = compileTestFile(source, testClass); return ClassFile.read(clazzFile); @@ -170,8 +178,12 @@ return f; } - protected File compileTestFile(File f, String testClass) { - int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.8", "-g", f.getPath() }); + protected File compileTestFile(File f, String testClass, String... extraParams) { + List<String> options = new ArrayList<>(); + options.addAll(Arrays.asList("-source", "1.8")); + options.addAll(Arrays.asList(extraParams)); + options.add(f.getPath()); + int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[options.size()])); if (rc != 0) throw new Error("compilation failed. rc=" + rc); String path;
--- a/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/referenceinfos/ExceptionParameters.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ /* * @test + * @bug 8028576 * @summary Test population of reference info for exception parameters * @author Werner Dietl * @compile -g Driver.java ReferenceInfoUtil.java ExceptionParameters.java
--- a/test/tools/javac/api/TestJavacTaskScanner.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/api/TestJavacTaskScanner.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 4813736 + * @bug 4813736 8013256 * @summary Additional functionality test of task and JSR 269 * @author Peter von der Ah\u00e9 * @library ./lib
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/api/taskListeners/EventsBalancedTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8040822 + * @summary Check that all TaskEvents are balanced. + */ + +import java.io.*; +import java.net.URI; +import java.util.*; +import java.util.Map.Entry; + +import javax.tools.*; + +import com.sun.source.util.*; +import com.sun.source.util.TaskEvent.Kind; +import com.sun.tools.javac.api.JavacTool; +import com.sun.tools.javac.comp.CompileStates.CompileState; + +public class EventsBalancedTest { + JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); + + public static void main(String... args) throws IOException { + new EventsBalancedTest().test(); + } + + void test() throws IOException { + TestSource a = new TestSource("B", "class B extends A { }"); + TestSource b = new TestSource("A", "abstract class A { }"); + + test(null, Arrays.asList(a, b)); + test(null, Arrays.asList(b, a)); + test(Arrays.asList("-XD-relax"), Arrays.asList(a, b)); + test(Arrays.asList("-XD-relax"), Arrays.asList(b, a)); + + for (CompileState stop : CompileState.values()) { + test(Arrays.asList("-XDshouldStopPolicyIfNoError=" + stop, + "-XDshouldStopPolicyIfError=" + stop), + Arrays.asList(a, b)); + test(Arrays.asList("-XDshouldStopPolicyIfNoError=" + stop, + "-XDshouldStopPolicyIfError=" + stop), + Arrays.asList(b, a)); + } + } + + void test(Iterable<String> options, Iterable<JavaFileObject> files) throws IOException { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + TestListener listener = new TestListener(); + JavacTask task = tool.getTask(pw, fm, null, options, null, files); + + task.setTaskListener(listener); + + task.call(); + + for (Entry<Kind, Integer> e : listener.kind2Count.entrySet()) { + if (e.getValue() != null && e.getValue() != 0) { + throw new IllegalStateException("Not balanced event: " + e.getKey()); + } + } + } + + static class TestListener implements TaskListener { + final Map<Kind, Integer> kind2Count = new HashMap<>(); + + int get(Kind k) { + Integer count = kind2Count.get(k); + + if (count == null) + kind2Count.put(k, count = 0); + + return count; + } + + @Override + public void started(TaskEvent e) { + kind2Count.put(e.getKind(), get(e.getKind()) + 1); + } + + @Override + public void finished(TaskEvent e) { + int count = get(e.getKind()); + + if (count <= 0) + throw new IllegalStateException("count<=0 for: " + e.getKind()); + + kind2Count.put(e.getKind(), count - 1); + } + + } + static class TestSource extends SimpleJavaFileObject { + final String content; + public TestSource(String fileName, String content) { + super(URI.create("myfo:/" + fileName + ".java"), JavaFileObject.Kind.SOURCE); + this.content = content; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return content; + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/classfiles/InnerClasses/SyntheticClasses.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** @test + * @bug 8034854 + * @summary Verify that the InnerClasses attribute has outer_class_info_index zero if it has + * inner_name_index zero (for synthetic classes) + * @compile SyntheticClasses.java + * @run main SyntheticClasses + */ + +import java.io.*; +import java.util.*; +import com.sun.tools.classfile.*; + +public class SyntheticClasses { + + public static void main(String[] args) throws IOException, ConstantPoolException { + new SyntheticClasses().run(); + } + + private void run() throws IOException, ConstantPoolException { + File testClasses = new File(System.getProperty("test.classes")); + for (File classFile : testClasses.listFiles(f -> f.getName().endsWith(".class"))) { + ClassFile cf = ClassFile.read(classFile); + if (cf.getName().matches(".*\\$[0-9]+")) { + EnclosingMethod_attribute encl = + (EnclosingMethod_attribute) cf.getAttribute(Attribute.EnclosingMethod); + if (encl != null) { + if (encl.method_index != 0) + throw new IllegalStateException("Invalid EnclosingMethod.method_index: " + + encl.method_index + "."); + } + } + InnerClasses_attribute attr = + (InnerClasses_attribute) cf.getAttribute(Attribute.InnerClasses); + if (attr != null) { + for (InnerClasses_attribute.Info info : attr.classes) { + if (cf.major_version < 51) + throw new IllegalStateException(); + if (info.inner_name_index == 0 && info.outer_class_info_index != 0) + throw new IllegalStateException("Invalid outer_class_info_index=" + + info.outer_class_info_index + + "; inner_name_index=" + + info.inner_name_index + "."); + } + } + } + } +} + +class SyntheticConstructorAccessTag { + + private static class A { + private A(){} + } + + public void test() { + new A(); + } +} + +class SyntheticEnumMapping { + private int convert(E e) { + switch (e) { + case A: return 0; + default: return -1; + } + } + enum E { A } +} + +interface SyntheticAssertionsDisabled { + public default void test() { + assert false; + } +}
--- a/test/tools/javac/defaultMethods/static/hiding/InterfaceMethodHidingTest.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/defaultMethods/static/hiding/InterfaceMethodHidingTest.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ * @bug 8005166 * @summary Add support for static interface methods * Smoke test for static interface method hiding + * @run main/timeout=600 InterfaceMethodHidingTest */ import com.sun.source.util.JavacTask;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defaultMethodsVisibility/DefaultMethodsNotVisibleForSourceLessThan8Test.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8029240 8030855 + * @summary Default methods not always visible under -source 7 + * Default methods should be visible under source previous to 8 + * @library /tools/javac/lib + * @build ToolBox + * @run main DefaultMethodsNotVisibleForSourceLessThan8Test + */ + +import java.nio.file.Files; +import java.nio.file.Paths; + +public class DefaultMethodsNotVisibleForSourceLessThan8Test { + // common definitions + + // this one should be compiled with source 8, the rest with source < 8 + static final String ISrc = + "interface I {\n" + + " default void m() {}\n" + + "}"; + + static final String JSrc = + "interface J extends I {}"; + + static final String ASrc = + "abstract class A implements I {}"; + + static final String BSrc = + "class B implements I {}"; + + // test legacy implementations + static final String C1Src = + "class C1 implements I {\n" + + " public void m() {}\n" + + "}"; + + static final String C2Src = + "class C2 implements J {\n" + + " public void m() {}\n" + + "}"; + + static final String C3Src = + "class C3 extends A {\n" + + " public void m() {}\n" + + "}"; + + static final String C4Src = + "class C4 extends B {\n" + + " public void m() {}\n" + + "}"; + + //test legacy invocations + static final String LegacyInvocationSrc = + "class LegacyInvocation {\n" + + " public static void test(I i, J j, A a, B b) {\n" + + " i.m();\n" + + " j.m();\n" + + " a.m();\n" + + " b.m();\n" + + " }\n" + + "}"; + + //test case super invocations + static final String SubASrc = + "class SubA extends A {\n" + + " public void test() {\n" + + " super.m();\n" + + " }\n" + + "}"; + + static final String SubBSrc = + "class SubB extends B {\n" + + " public void test() {\n" + + " super.m();\n" + + " }\n" + + "}"; + + public static void main(String[] args) throws Exception { + String[] sources = new String[] { + "1.2", + "1.3", + "1.4", + "1.5", + "1.6", + "1.7", + }; + for (String source : sources) { + new DefaultMethodsNotVisibleForSourceLessThan8Test().run(source); + } + } + + String outDir; + String source; + + void run(String source) throws Exception { + this.source = source; + outDir = "out" + source.replace('.', '_'); + testsPreparation(); + testLegacyImplementations(); + testLegacyInvocations(); + testSuperInvocations(); + } + + void testsPreparation() throws Exception { + Files.createDirectory(Paths.get(outDir)); + + /* as an extra check let's make sure that interface 'I' can't be compiled + * with source < 8 + */ + ToolBox.JavaToolArgs javacArgs = + new ToolBox.JavaToolArgs(ToolBox.Expect.FAIL) + .setOptions("-d", outDir, "-source", source) + .setSources(ISrc); + ToolBox.javac(javacArgs); + + //but it should compile with source >= 8 + javacArgs = + new ToolBox.JavaToolArgs() + .setOptions("-d", outDir) + .setSources(ISrc); + ToolBox.javac(javacArgs); + + javacArgs = + new ToolBox.JavaToolArgs() + .setOptions("-cp", outDir, "-d", outDir, "-source", source) + .setSources(JSrc, ASrc, BSrc); + ToolBox.javac(javacArgs); + } + + void testLegacyImplementations() throws Exception { + //compile C1-4 + ToolBox.JavaToolArgs javacArgs = + new ToolBox.JavaToolArgs() + .setOptions("-cp", outDir, "-d", outDir, "-source", source) + .setSources(C1Src, C2Src, C3Src, C4Src); + ToolBox.javac(javacArgs); + } + + void testLegacyInvocations() throws Exception { + //compile LegacyInvocation + ToolBox.JavaToolArgs javacArgs = + new ToolBox.JavaToolArgs() + .setOptions("-cp", outDir, "-d", outDir, "-source", source) + .setSources(LegacyInvocationSrc); + ToolBox.javac(javacArgs); + } + + void testSuperInvocations() throws Exception { + //compile SubA, SubB + ToolBox.JavaToolArgs javacArgs = + new ToolBox.JavaToolArgs() + .setOptions("-cp", outDir, "-d", outDir, "-source", source) + .setSources(SubASrc, SubBSrc); + ToolBox.javac(javacArgs); + } +}
--- a/test/tools/javac/diags/examples.not-yet.txt Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/diags/examples.not-yet.txt Thu May 29 13:46:36 2014 -0700 @@ -110,4 +110,5 @@ compiler.warn.unknown.enum.constant # in bad class file compiler.warn.unknown.enum.constant.reason # in bad class file compiler.warn.override.equals.but.not.hashcode # when a class overrides equals but not hashCode method from Object - +compiler.err.cant.inherit.from.anon # error for subclass of anonymous class +compiler.misc.bad.const.pool.entry # constant pool entry has wrong type
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/AnnotationsAfterTypeParamsNotSupportedInSource.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.annotations.after.type.params.not.supported.in.source +// key: compiler.warn.source.no.bootclasspath +// options: -source 7 + +@interface Anno { } + +class AnnotationsAfterTypeParamsNotSupportedInSource { + <T> @Anno int m() { + return 0; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/LambdaBodyNeitherValueNorVoidCompatible.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.lambda.body.neither.value.nor.void.compatible +// key: compiler.err.cant.apply.symbol +// key: compiler.misc.incompatible.ret.type.in.lambda +// key: compiler.misc.missing.ret.val +// key: compiler.misc.no.conforming.assignment.exists + +class LambdaBodyNeitherValueNorVoidCompatible { + interface I { + String f(String x); + } + + static void foo(I i) {} + + void m() { + foo((x) -> { + if (x == null) { + return; + } else { + return x; + } + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/WarnSerializableLambda.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.warn.access.to.sensitive.member.from.serializable.element +// options: -XDwarnOnAccessToSensitiveMembers + +import java.io.Serializable; + +public class WarnSerializableLambda { + interface SAM { + void apply(String s); + } + + private void m1() { + SAM s = (SAM & Serializable) c -> { + packageField = ""; + }; + } + + String packageField; +}
--- a/test/tools/javac/doctree/SeeTest.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/doctree/SeeTest.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 7021614 + * @bug 7021614 8031212 * @summary extend com.sun.source API to support parsing javadoc comments * @build DocCommentTester * @run main DocCommentTester SeeTest.java @@ -41,9 +41,9 @@ Text[TEXT, pos:1, abc.] body: empty block tags: 1 - Erroneous[ERRONEOUS, pos:7 - code: compiler.err.dc.unexpected.content - body: @see_"String" + See[SEE, pos:7 + reference: 1 + Text[TEXT, pos:12, "String"] ] ] */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/flow/T8030218/CompileTimeErrorForNonAssignedStaticFieldTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,29 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8030218 + * @summary javac, compile time error isn't shown when final static field is not assigned, follow-up + * @compile/fail/ref=CompileTimeErrorForNonAssignedStaticFieldTest.out -XDrawDiagnostics CompileTimeErrorForNonAssignedStaticFieldTest.java + */ + +public class CompileTimeErrorForNonAssignedStaticFieldTest { + private final static int i; + + public CompileTimeErrorForNonAssignedStaticFieldTest() + throws InstantiationException { + throw new InstantiationException("Can't instantiate"); + } + + static class Inner { + private final int j; + public Inner(int x) + throws InstantiationException { + if (x == 0) { + throw new InstantiationException("Can't instantiate"); + } else { + j = 1; + } + System.out.println(j); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/flow/T8030218/CompileTimeErrorForNonAssignedStaticFieldTest.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,2 @@ +CompileTimeErrorForNonAssignedStaticFieldTest.java:14:5: compiler.err.var.might.not.have.been.initialized: i +1 error
--- a/test/tools/javac/generics/inference/7086586/T7086586.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/generics/inference/7086586/T7086586.out Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ -T7086586.java:14:20: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) -T7086586.java:15:20: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) -T7086586.java:16:23: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) -T7086586.java:17:9: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)) +T7086586.java:14:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.captureof: 1, ?, java.lang.String) +T7086586.java:15:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.captureof: 1, ?, java.lang.Number) +T7086586.java:16:31: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.captureof: 1, ?, java.lang.Exception) +T7086586.java:17:13: compiler.err.cant.resolve.location.args: kindname.method, nonExistentMethod, , , (compiler.misc.location: kindname.interface, java.util.List<compiler.misc.type.captureof: 1, ?>, null) 4 errors
--- a/test/tools/javac/generics/inference/7086586/T7086586b.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/generics/inference/7086586/T7086586b.java Thu May 29 13:46:36 2014 -0700 @@ -23,9 +23,10 @@ /* * @test - * @bug 7086586 + * @bug 7086586 8033718 * - * @summary Inference producing null type argument + * @summary Inference producing null type argument; inference ignores capture + * variable as upper bound */ import java.util.List; @@ -40,8 +41,8 @@ assertionCount++; } - <T> void m(List<? super T> dummy) { assertTrue(false); } - <T> void m(Object dummy) { assertTrue(true); } + <T> void m(List<? super T> dummy) { assertTrue(true); } + <T> void m(Object dummy) { assertTrue(false); } void test(List<?> l) { m(l);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/LowerBoundGLB.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8033718 + * @author dlsmith + * @summary GLB for two capture variables with lower bounds + * @compile LowerBoundGLB.java + */ + +public class LowerBoundGLB { + + interface Box<T> { + T get(); + void set(T arg); + } + + <T> T doGLB(Box<? super T> b1, Box<? super T> b2) { + return null; + } + + void test(Box<? super String> l1, Box<? super CharSequence> l2) { + doGLB(l1, l2).substring(3); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/T8028503/PrimitiveTypeInBoundForMethodRefTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8028503 + * @summary javac, for method references a primitive type can be added as a bound + * @compile PrimitiveTypeInBoundForMethodRefTest.java + */ + +class PrimitiveTypeInBoundForMethodRefTest { + + interface Mapper<T, U> { + U map(T t); + } + + static <U> Iterable<U> map(Mapper<String, U> mapper) { + return null; + } + + static void test() { + Iterable<Integer> map = map(PrimitiveTypeInBoundForMethodRefTest::length); + } + + public static <T> int length(String s) { + return 0; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/typevars/IntersectionSubVar.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8042656 + * @summary Subtyping for intersection types containing type variables + * @compile IntersectionSubVar.java + */ + +class IntersectionSubVar { + + interface Box<T> { + void set(T arg); + T get(); + } + + <I> Box<I> glb(Box<? super I> arg1, Box<? super I> arg2) { + return null; + } + + <E extends Cloneable> void takeBox(Box<? super E> box) {} + + <T> void test(Box<T> arg1, Box<Cloneable> arg2, Box<? super T> arg3) { + T t = glb(arg1, arg2).get(); // assign T&Cloneable to T + takeBox(arg3); // inference tests Box<CAP> <: Box<? super CAP&Cloneable> + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/EagerReturnTypeResolutionTesta.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8030741 + * @summary Inference: implement eager resolution of return types, consistent with JDK-8028800 + * @compile EagerReturnTypeResolutionTesta.java + */ + +public class EagerReturnTypeResolutionTesta { + + abstract class Test1<T>{ + abstract <S> S foo(S x, S y); + <S extends Number & Comparable<? extends Number>> void baz(Test1<S> a){} + + void bar(Test1<Long> x, Test1<Integer> y){ + baz(foo(x, y)); + } + } + + abstract class Test2<T>{ + abstract <S> S foo(S x, S y); + abstract <S1> void baz(Test2<S1> a); + + void bar(Test2<Integer> y, Test2<Long> x){ + baz(foo(x, y)); + } + } + + abstract class Test3<T>{ + abstract <S> S foo(S x, S y); + <T extends Number & Comparable<?>, + S extends Number & Comparable<? extends T>> void baz(Test3<S> a){} + + void bar(Test3<Long> x, Test3<Integer> y){ + baz(foo(x, y)); + } + } + + abstract class Test4 { + abstract class A0<T> {} + + abstract class A1<T> extends A0<T> {} + + abstract class A2<T> extends A0<T> {} + + abstract <S> S foo(S x, S y); + abstract <S1> void baz(A0<S1> a); + + void bar(A2<Integer> y, A1<Long> x){ + baz(foo(x, y)); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/EagerReturnTypeResolutionTestb.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,182 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8030741 + * @summary Inference: implement eager resolution of return types, consistent with JDK-8028800 + * @compile/fail/ref=EagerReturnTypeResolutionTestb.out -XDrawDiagnostics EagerReturnTypeResolutionTestb.java + * @author Dan Smith + */ + +import java.util.List; + +public class EagerReturnTypeResolutionTestb { + interface I<S> {} + interface J<S> extends I<S> {} + interface K extends I<String> {} + interface L<S> extends I {} + + <T> T lower(List<? extends T> l) { return null; } + <T> T lower2(List<? extends T> l1, List<? extends T> l2) { return null; } + + <T> T upper(List<? super T> l) { return null; } + <T> T upper2(List<? super T> l1, List<? super T> l2) { return null; } + + <T> T eq(List<T> l) { return null; } + <T> T eq2(List<T> l1, List<T> l2) { return null; } + + <X> void takeI(I<X> i) {} + void takeIString(I<String> i) {} + I<String> iStringField; + + void takeLong(long arg) {} + long longField; + + void testSimpleCaptureOK(List<I<?>> i1) { + takeI(lower(i1)); // ok* + takeI(eq(i1)); // ok* + takeI(upper(i1)); // ok, no capture + takeIString(upper(i1)); // ok + iStringField = upper(i1); // ok + } + + void testSimpleCaptureKO(List<I<?>> i1) { + takeIString(lower(i1)); // ERROR + takeIString(eq(i1)); // ERROR + iStringField = lower(i1); // ERROR + iStringField = eq(i1); // ERROR + } + + void testMultiCaptureOK(List<I<String>> i1, List<I<Integer>> i2, List<I<?>> i3, + List<J<String>> j1, List<J<Integer>> j2, List<K> k1) { + /* Lines marked with JDK-8029002 should be uncommented once this bug is + * fixed + */ + takeI(lower2(i1, i2)); // ok* + takeI(lower2(i1, i3)); // ok* + takeI(upper2(i1, i3)); // ok, no capture* JDK-8029002 + + takeIString(upper2(i1, i3)); // ok, no capture + iStringField = upper2(i1, i3); // ok, no capture + + takeI(lower2(j1, j2)); // ok* + takeI(lower2(j1, k1)); // ok, no capture + takeI(upper2(j1, k1)); // ok, no capture* JDK-8029002 + + takeIString(lower2(j1, k1)); // ok, no capture + takeIString(upper2(j1, k1)); // ok, no capture + + iStringField = lower2(j1, k1); // ok, no capture + iStringField = upper2(j1, k1); // ok, no capture + takeI(lower2(j2, k1)); // ok* + } + + void testMultiCaptureKO(List<I<String>> i1, List<I<Integer>> i2, List<I<?>> i3, + List<J<String>> j1, List<J<Integer>> j2, List<K> k1) { + takeI(eq2(i1, i2)); // ERROR, bad bounds + takeI(upper2(i1, i2)); // ERROR, bad bounds + + takeIString(lower2(i1, i2)); // ERROR + takeIString(eq2(i1, i2)); // ERROR, bad bounds + takeIString(upper2(i1, i2)); // ERROR, bad bounds + + iStringField = lower2(i1, i2); // ERROR + iStringField = eq2(i1, i2); // ERROR, bad bounds + iStringField = upper2(i1, i2); // ERROR, bad bounds + + takeI(eq2(i1, i3)); // ERROR, bad bounds + takeIString(lower2(i1, i3)); // ERROR + takeIString(eq2(i1, i3)); // ERROR, bad bounds + + iStringField = lower2(i1, i3); // ERROR + iStringField = eq2(i1, i3); // ERROR, bad bounds + takeI(eq2(j1, j2)); // ERROR, bad bounds + takeI(upper2(j1, j2)); // ERROR, bad bounds + + takeIString(lower2(j1, j2)); // ERROR + takeIString(eq2(j1, j2)); // ERROR, bad bounds + takeIString(upper2(j1, j2)); // ERROR, bad bounds + + iStringField = lower2(j1, j2); // ERROR + iStringField = eq2(j1, j2); // ERROR, bad bounds + iStringField = upper2(j1, j2); // ERROR, bad bounds + + takeI(eq2(j1, k1)); // ERROR, bad bounds + takeIString(eq2(j1, k1)); // ERROR, bad bounds + iStringField = eq2(j1, k1); // ERROR, bad bounds + takeI(eq2(j2, k1)); // ERROR, bad bounds + takeI(upper2(j2, k1)); // ERROR, bad bounds; actual: no error, see JDK-8037474 + + takeIString(lower2(j2, k1)); // ERROR + takeIString(eq2(j2, k1)); // ERROR, bad bounds + takeIString(upper2(j2, k1)); // ERROR, bad bounds + + iStringField = lower2(j2, k1); // ERROR + iStringField = eq2(j2, k1); // ERROR, bad bounds + iStringField = upper2(j2, k1); // ERROR, bad bounds + } + + void testRawOK(List<I> i1, List<J> j1, List<L<String>> l1) { + takeI(lower(i1)); // ok, unchecked + takeI(eq(i1)); // ok, unchecked + takeI(upper(i1)); // ok, no capture, not unchecked + + takeIString(lower(i1)); // ok, unchecked + takeIString(eq(i1)); // ok, unchecked + takeIString(upper(i1)); // ok, no capture, not unchecked + + iStringField = lower(i1); // ok, unchecked + iStringField = eq(i1); // ok, unchecked + iStringField = upper(i1); // ok, no capture, not unchecked + + takeI(lower(j1)); // ok, unchecked + takeI(eq(j1)); // ok, unchecked + takeI(upper(j1)); // bad bounds? -- spec is unclear + + takeIString(lower(j1)); // ok, unchecked + takeIString(eq(j1)); // ok, unchecked + takeIString(upper(j1)); // bad bounds? -- spec is unclear + + iStringField = lower(j1); // ok, unchecked + iStringField = eq(j1); // ok, unchecked + iStringField = upper(j1); // bad bounds? -- spec is unclear + + takeI(lower(l1)); // ok, unchecked + takeI(eq(l1)); // ok, unchecked + takeI(upper(l1)); // bad bounds? -- spec is unclear + + takeIString(lower(l1)); // ok, unchecked + takeIString(eq(l1)); // ok, unchecked + takeIString(upper(l1)); // bad bounds? -- spec is unclear + + iStringField = lower(l1); // ok, unchecked + iStringField = eq(l1); // ok, unchecked + iStringField = upper(l1); // bad bounds? -- spec is unclear + } + + void testPrimOK(List<Integer> i1, List<Long> l1, List<Double> d1) { + takeLong(lower(i1)); // ok + takeLong(eq(i1)); // ok + takeLong(upper(i1)); // ok* + + longField = lower(i1); // ok + longField = eq(i1); // ok + longField = upper(i1); // ok* + + takeLong(lower(l1)); // ok + takeLong(eq(l1)); // ok + takeLong(upper(l1)); // ok + + longField = lower(l1); // ok + longField = eq(l1); // ok + longField = upper(l1); // ok + } + + void testPrimKO(List<Integer> i1, List<Long> l1, List<Double> d1) { + takeLong(lower(d1)); // ERROR + takeLong(eq(d1)); // ERROR + takeLong(upper(d1)); // ERROR + + longField = lower(d1); // ERROR + longField = eq(d1); // ERROR + longField = upper(d1); // ERROR + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/EagerReturnTypeResolutionTestb.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,45 @@ +EagerReturnTypeResolutionTestb.java:42:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ?>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) +EagerReturnTypeResolutionTestb.java:43:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ?>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) +EagerReturnTypeResolutionTestb.java:44:29: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:45:26: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:74:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>) +EagerReturnTypeResolutionTestb.java:75:15: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:77:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) +EagerReturnTypeResolutionTestb.java:78:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>) +EagerReturnTypeResolutionTestb.java:79:21: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:81:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:82:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>) +EagerReturnTypeResolutionTestb.java:83:24: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<java.lang.Integer>, EagerReturnTypeResolutionTestb.I<java.lang.Integer>,EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:85:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<?>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<?>,EagerReturnTypeResolutionTestb.I<java.lang.String>) +EagerReturnTypeResolutionTestb.java:86:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ?>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) +EagerReturnTypeResolutionTestb.java:87:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<?>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<?>,EagerReturnTypeResolutionTestb.I<java.lang.String>) +EagerReturnTypeResolutionTestb.java:89:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:90:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.I<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.I<?>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.I<?>, EagerReturnTypeResolutionTestb.I<?>,EagerReturnTypeResolutionTestb.I<java.lang.String>) +EagerReturnTypeResolutionTestb.java:91:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>) +EagerReturnTypeResolutionTestb.java:92:15: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:94:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.J<compiler.misc.type.captureof: 1, ? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) +EagerReturnTypeResolutionTestb.java:95:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>) +EagerReturnTypeResolutionTestb.java:96:21: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:98:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:99:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>) +EagerReturnTypeResolutionTestb.java:100:24: compiler.err.cant.apply.symbol: kindname.method, upper2, java.util.List<? super T>,java.util.List<? super T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.J<java.lang.Integer>, EagerReturnTypeResolutionTestb.J<java.lang.Integer>,EagerReturnTypeResolutionTestb.J<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:102:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.String>) +EagerReturnTypeResolutionTestb.java:103:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.String>) +EagerReturnTypeResolutionTestb.java:104:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.String>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.String>) +EagerReturnTypeResolutionTestb.java:105:15: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>) +EagerReturnTypeResolutionTestb.java:106:9: compiler.err.cant.apply.symbol: kindname.method, takeI, EagerReturnTypeResolutionTestb.I<X>, java.lang.Object&EagerReturnTypeResolutionTestb.J<java.lang.Integer>&EagerReturnTypeResolutionTestb.K, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: java.lang.Integer, java.lang.Integer,java.lang.String) +EagerReturnTypeResolutionTestb.java:108:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, EagerReturnTypeResolutionTestb.I<compiler.misc.type.captureof: 1, ? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object)) +EagerReturnTypeResolutionTestb.java:109:21: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>) +EagerReturnTypeResolutionTestb.java:110:9: compiler.err.cant.apply.symbol: kindname.method, takeIString, EagerReturnTypeResolutionTestb.I<java.lang.String>, java.lang.Object&EagerReturnTypeResolutionTestb.J<java.lang.Integer>&EagerReturnTypeResolutionTestb.K, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object&EagerReturnTypeResolutionTestb.J<java.lang.Integer>&EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.I<java.lang.String>,EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>,java.lang.Object)) +EagerReturnTypeResolutionTestb.java:112:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: EagerReturnTypeResolutionTestb.I<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>>, EagerReturnTypeResolutionTestb.I<java.lang.String>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:113:24: compiler.err.cant.apply.symbol: kindname.method, eq2, java.util.List<T>,java.util.List<T>, java.util.List<EagerReturnTypeResolutionTestb.J<java.lang.Integer>>,java.util.List<EagerReturnTypeResolutionTestb.K>, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.inferred.do.not.conform.to.eq.bounds: EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>) +EagerReturnTypeResolutionTestb.java:114:30: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Object&EagerReturnTypeResolutionTestb.J<java.lang.Integer>&EagerReturnTypeResolutionTestb.K, EagerReturnTypeResolutionTestb.I<java.lang.String>,EagerReturnTypeResolutionTestb.K,EagerReturnTypeResolutionTestb.J<java.lang.Integer>,java.lang.Object) +EagerReturnTypeResolutionTestb.java:174:9: compiler.err.cant.apply.symbol: kindname.method, takeLong, long, java.lang.Double, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , T, long)) +EagerReturnTypeResolutionTestb.java:175:9: compiler.err.cant.apply.symbol: kindname.method, takeLong, long, java.lang.Double, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , T, long)) +EagerReturnTypeResolutionTestb.java:176:9: compiler.err.cant.apply.symbol: kindname.method, takeLong, long, java.lang.Double, kindname.class, EagerReturnTypeResolutionTestb, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , T, long)) +EagerReturnTypeResolutionTestb.java:178:26: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.instance.exists: , T, long) +EagerReturnTypeResolutionTestb.java:179:23: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.instance.exists: , T, long) +EagerReturnTypeResolutionTestb.java:180:26: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.instance.exists: , T, long) +- compiler.note.unchecked.filename: EagerReturnTypeResolutionTestb.java +- compiler.note.unchecked.recompile +42 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/PrimitiveTypeBoxingTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,25 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8030741 + * @summary Inference: implement eager resolution of return types, consistent with JDK-8028800 + * @compile/fail/ref=PrimitiveTypeBoxingTest.out -XDrawDiagnostics PrimitiveTypeBoxingTest.java + */ + +public class PrimitiveTypeBoxingTest { + + static void foo(long arg) {} + static void bar(int arg) {} + + interface F<X> { void get(X arg); } + + <Z> void m1(F<Z> f, Z arg) {} + <Z> void m2(Z arg, F<Z> f) {} + + void test() { + m1(PrimitiveTypeBoxingTest::foo, 23); // expected: error + m2(23, PrimitiveTypeBoxingTest::foo); // expected: error + + m1(PrimitiveTypeBoxingTest::bar, 23); // expected: success + m2(23, PrimitiveTypeBoxingTest::bar); // expected: success + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/inference/EagerReturnTypeResolution/PrimitiveTypeBoxingTest.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,3 @@ +PrimitiveTypeBoxingTest.java:19:9: compiler.err.cant.apply.symbol: kindname.method, m1, PrimitiveTypeBoxingTest.F<Z>,Z, @490,int, kindname.class, PrimitiveTypeBoxingTest, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.Long,java.lang.Object) +PrimitiveTypeBoxingTest.java:20:9: compiler.err.cant.apply.symbol: kindname.method, m2, Z,PrimitiveTypeBoxingTest.F<Z>, int,@559, kindname.class, PrimitiveTypeBoxingTest, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.Long,java.lang.Object) +2 errors
--- a/test/tools/javac/lambda/ErroneousLambdaExpr.java Mon May 19 22:00:11 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2012, 2013 Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 8003280 - * @summary Add lambda tests - * stale state after speculative attribution round leads to missing classfiles - * @compile/fail/ref=ErroneousLambdaExpr.out -XDrawDiagnostics ErroneousLambdaExpr.java - */ -public class ErroneousLambdaExpr<T> { - - static int assertionCount = 0; - - static void assertTrue(boolean cond) { - assertionCount++; - if (!cond) - throw new AssertionError(); - } - - interface SAM1<X> { - X m(X t, String s); - } - - interface SAM2 { - void m(String s, int i); - } - - interface SAM3<X> { - X m(X t, String s, int i); - } - - void call(SAM1<T> s1) { assertTrue(true); } - - void call(SAM2 s2) { assertTrue(false); } - - void call(SAM3<T> s3) { assertTrue(false); } - - public static void main(String[] args) { - ErroneousLambdaExpr<StringBuilder> test = - new ErroneousLambdaExpr<>(); - - test.call((builder, string) -> { builder.append(string); return builder; }); - assertTrue(assertionCount == 1); - } -}
--- a/test/tools/javac/lambda/ErroneousLambdaExpr.out Mon May 19 22:00:11 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -ErroneousLambdaExpr.java:63:13: compiler.err.ref.ambiguous: call, kindname.method, call(ErroneousLambdaExpr.SAM1<T>), ErroneousLambdaExpr, kindname.method, call(ErroneousLambdaExpr.SAM2), ErroneousLambdaExpr -1 error
--- a/test/tools/javac/lambda/FunctionalInterfaceConversionTest.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/FunctionalInterfaceConversionTest.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ * @author Maurizio Cimadamore * @library ../lib * @build JavacTestingAbstractThreadedTest - * @run main/othervm FunctionalInterfaceConversionTest + * @run main/timeout=600/othervm FunctionalInterfaceConversionTest */ // use /othervm to avoid jtreg timeout issues (CODETOOLS-7900047)
--- a/test/tools/javac/lambda/InnerConstructor.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/InnerConstructor.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 8003280 + * @bug 8003280 8003306 * @summary Add lambda tests * Regression test JDK-8003306 inner class constructor in lambda * @author Robert Field
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/LambdaExprLeadsToMissingClassFilesTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012, 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8003280 + * @summary Add lambda tests + * stale state after speculative attribution round leads to missing classfiles + */ +public class LambdaExprLeadsToMissingClassFilesTest<T> { + + static int assertionCount = 0; + + static void assertTrue(boolean cond) { + assertionCount++; + if (!cond) { + throw new AssertionError(); + } + } + + interface SAM1<X> { + X m(X t, String s); + } + + interface SAM2 { + void m(String s, int i); + } + + interface SAM3<X> { + X m(X t, String s, int i); + } + + void call(SAM1<T> s1) { assertTrue(true); } + + void call(SAM2 s2) { assertTrue(false); } + + void call(SAM3<T> s3) { assertTrue(false); } + + public static void main(String[] args) { + LambdaExprLeadsToMissingClassFilesTest<StringBuilder> test = + new LambdaExprLeadsToMissingClassFilesTest<>(); + + test.call((builder, string) -> { builder.append(string); return builder; }); + assertTrue(assertionCount == 1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/LambdaLocalTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8029725 + * @summary Lambda reference to containing local class causes javac infinite recursion + * @author Robert Field + * @run main LambdaLocalTest + */ + +public class LambdaLocalTest { + interface F {void f();} + + static F f; + static StringBuffer sb = new StringBuffer(); + + static void assertEquals(Object val, Object expected) { + if (!val.equals(expected)) { + throw new AssertionError("expected '" + expected + "' got '" + val + "'"); + } + } + + public static void main(String[] args) { + class Local { + public Local() { + f = () -> new Local(); + sb.append("+"); + } + } + new Local(); + f.f(); + assertEquals(sb.toString(), "++"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/LambdaMultiCatchTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8036942 + * @summary javac generates incorrect exception table for multi-catch statements inside a lambda + * @run main LambdaMultiCatchTest + */ + +import java.io.IOException; +import java.util.function.Function; + +public class LambdaMultiCatchTest { + public static void main(String[] args) { + Function<String,String> fi = x -> { + String result = "nada"; + try { + switch (x) { + case "IO": throw new IOException(); + case "Illegal": throw new IllegalArgumentException(); + case "Run": throw new RuntimeException(); + } + } catch (IOException|IllegalArgumentException ex) { + result = "IO/Illegal"; + } catch (Exception ex) { + result = "Any"; + }; + return result; + }; + String val = fi.apply("Run"); + if (!val.equals("Any")) { + throw new AssertionError("Fail: Expected 'Any' but got '" + val + "'"); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/LambdaOuterLocalTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8029725 + * @summary Lambda reference to containing local class causes javac infinite recursion + * @author Robert Field + * @run main LambdaOuterLocalTest + */ + +public class LambdaOuterLocalTest { + interface F {void f();} + + static F f; + static StringBuffer sb = new StringBuffer(); + + static void assertEquals(Object val, Object expected) { + if (!val.equals(expected)) { + throw new AssertionError("expected '" + expected + "' got '" + val + "'"); + } + } + + public static void main(String[] args) { + class Local1 { + public Local1() { + class Local2 { + public Local2() { + f = () -> new Local1(); + sb.append("2"); + } + } + sb.append("1"); + new Local2(); + } + } + new Local1(); + f.f(); + assertEquals(sb.toString(), "1212"); + } +}
--- a/test/tools/javac/lambda/MethodReference42.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/MethodReference42.out Thu May 29 13:46:36 2014 -0700 @@ -1,4 +1,4 @@ -MethodReference42.java:38:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference42.SAM1, @811, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) -MethodReference42.java:40:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference42.SAM3, @855, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number)) +MethodReference42.java:38:11: compiler.err.cant.apply.symbol: kindname.method, m1, MethodReference42.SAM1, @811, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number))) +MethodReference42.java:40:11: compiler.err.cant.apply.symbol: kindname.method, m3, MethodReference42.SAM3, @855, kindname.class, MethodReference42, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number))) MethodReference42.java:41:9: compiler.err.ref.ambiguous: m4, kindname.method, m4(MethodReference42.SAM2), MethodReference42, kindname.method, m4(MethodReference42.SAM3), MethodReference42 3 errors
--- a/test/tools/javac/lambda/MethodReference44.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/MethodReference44.out Thu May 29 13:46:36 2014 -0700 @@ -1,4 +1,4 @@ -MethodReference44.java:40:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference44.SAM1, @864, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number)) -MethodReference44.java:42:11: compiler.err.cant.apply.symbol: kindname.method, g3, MethodReference44.SAM3, @932, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number)) +MethodReference44.java:40:11: compiler.err.cant.apply.symbol: kindname.method, g1, MethodReference44.SAM1, @864, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String, java.lang.Number))) +MethodReference44.java:42:11: compiler.err.cant.apply.symbol: kindname.method, g3, MethodReference44.SAM3, @932, kindname.class, MethodReference44, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.Object, java.lang.Number))) MethodReference44.java:43:9: compiler.err.ref.ambiguous: g4, kindname.method, g4(MethodReference44.SAM2), MethodReference44, kindname.method, g4(MethodReference44.SAM3), MethodReference44 3 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific09.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,81 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8029718 + * @summary Should always use lambda body structure to disambiguate overload resolution + * @compile/fail/ref=MostSpecific09.out -XDrawDiagnostics -XDshouldStopPolicy=ATTR -XDverboseResolution=applicable,success MostSpecific09.java + */ + +class MostSpecific09 { + + interface I { + String xoo(String x); + } + + interface J { + void xoo(int x); + } + + static void foo(I i) {} + static void foo(J j) {} + + static void moo(I i) {} + static void moo(J j) {} + + void m() { + foo((x) -> { return x += 1; }); + foo((x) -> { return ""; }); + foo((x) -> { System.out.println(""); }); + foo((x) -> { return ""; System.out.println(""); }); + foo((x) -> { throw new RuntimeException(); }); + foo((x) -> { while (true); }); + + foo((x) -> x += 1); + foo((x) -> ""); + } + + /* any return statement that is not in the body of the lambda but in an + * inner class or another lambda should be ignored for value void compatibility + * determination. + */ + void m1() { + boolean cond = true; + foo((x) -> { + if (cond) { + return ""; + } + System.out.println(""); + }); + + foo((x)->{ + class Bar { + String m() { + return "from Bar.m()"; + } + } + class Boo { + Bar b = new Bar (){ + String m() { + return "from Bar$1.m()"; + } + }; + } + moo((y) -> { return ""; }); + return; + }); + + foo((x)->{ + class Bar { + void m() {} + } + class Boo { + Bar b = new Bar (){ + void m() { + return; + } + }; + } + moo((y) -> { System.out.println(""); }); + return ""; + }); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific09.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,27 @@ +MostSpecific09.java:25:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.I), null)} +MostSpecific09.java:26:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.I), null)} +MostSpecific09.java:27:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.J), null)} +MostSpecific09.java:27:32: compiler.note.verbose.resolve.multi: println, java.io.PrintStream, 1, BASIC, java.lang.String, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, println(java.lang.Object), null),(compiler.misc.applicable.method.found: 1, println(java.lang.String), null)} +MostSpecific09.java:28:13: compiler.err.lambda.body.neither.value.nor.void.compatible +MostSpecific09.java:28:9: compiler.err.cant.apply.symbols: kindname.method, foo, @680,{(compiler.misc.inapplicable.method: kindname.method, MostSpecific09, foo(MostSpecific09.I), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.missing.ret.val: java.lang.String)))),(compiler.misc.inapplicable.method: kindname.method, MostSpecific09, foo(MostSpecific09.J), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.unexpected.ret.val)))} +MostSpecific09.java:28:43: compiler.note.verbose.resolve.multi: println, java.io.PrintStream, 1, BASIC, java.lang.String, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, println(java.lang.Object), null),(compiler.misc.applicable.method.found: 1, println(java.lang.String), null)} +MostSpecific09.java:29:9: compiler.err.ref.ambiguous: foo, kindname.method, foo(MostSpecific09.I), MostSpecific09, kindname.method, foo(MostSpecific09.J), MostSpecific09 +MostSpecific09.java:29:28: compiler.note.verbose.resolve.multi: <init>, java.lang.RuntimeException, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, java.lang.RuntimeException(), null)} +MostSpecific09.java:30:9: compiler.err.ref.ambiguous: foo, kindname.method, foo(MostSpecific09.I), MostSpecific09, kindname.method, foo(MostSpecific09.J), MostSpecific09 +MostSpecific09.java:32:9: compiler.err.ref.ambiguous: foo, kindname.method, foo(MostSpecific09.I), MostSpecific09, kindname.method, foo(MostSpecific09.J), MostSpecific09 +MostSpecific09.java:33:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.I), null)} +MostSpecific09.java:42:13: compiler.err.lambda.body.neither.value.nor.void.compatible +MostSpecific09.java:42:9: compiler.err.cant.apply.symbols: kindname.method, foo, @1129,{(compiler.misc.inapplicable.method: kindname.method, MostSpecific09, foo(MostSpecific09.I), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.missing.ret.val: java.lang.String)))),(compiler.misc.inapplicable.method: kindname.method, MostSpecific09, foo(MostSpecific09.J), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.unexpected.ret.val)))} +MostSpecific09.java:46:23: compiler.note.verbose.resolve.multi: println, java.io.PrintStream, 1, BASIC, java.lang.String, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, println(java.lang.Object), null),(compiler.misc.applicable.method.found: 1, println(java.lang.String), null)} +MostSpecific09.java:49:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.J), null)} +MostSpecific09.java:56:25: compiler.note.verbose.resolve.multi: <init>, Bar, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, Bar(), null)} +MostSpecific09.java:56:35: compiler.note.verbose.resolve.multi: <init>, Bar, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, Bar(), null)} +MostSpecific09.java:56:25: compiler.note.verbose.resolve.multi: <init>, compiler.misc.anonymous.class: MostSpecific09$1Boo$1, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, compiler.misc.anonymous.class: MostSpecific09$1Boo$1(), null)} +MostSpecific09.java:62:13: compiler.note.verbose.resolve.multi: moo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, moo(MostSpecific09.I), null)} +MostSpecific09.java:66:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.I), null)} +MostSpecific09.java:71:25: compiler.note.verbose.resolve.multi: <init>, Bar, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, Bar(), null)} +MostSpecific09.java:71:35: compiler.note.verbose.resolve.multi: <init>, Bar, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, Bar(), null)} +MostSpecific09.java:71:25: compiler.note.verbose.resolve.multi: <init>, compiler.misc.anonymous.class: MostSpecific09$2Boo$1, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, compiler.misc.anonymous.class: MostSpecific09$2Boo$1(), null)} +MostSpecific09.java:77:13: compiler.note.verbose.resolve.multi: moo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, moo(MostSpecific09.J), null)} +MostSpecific09.java:77:36: compiler.note.verbose.resolve.multi: println, java.io.PrintStream, 1, BASIC, java.lang.String, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, println(java.lang.Object), null),(compiler.misc.applicable.method.found: 1, println(java.lang.String), null)} +7 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific10.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8034223 + * @summary Structural most-specific logic for lambdas, method refs, parens, and conditionals + * @compile MostSpecific10.java + */ +class MostSpecific10 { + + interface GetInt { + int get(); + } + + interface GetInteger { + Integer get(); + } + + void m(GetInt getter) {} + void m(GetInteger getter) {} + + void test(boolean cond) { + m(() -> 23); + m("abc"::length); + m(( () -> 23 )); + m(( "abc"::length )); + m(cond ? () -> 23 : "abc"::length); + m(( cond ? () -> 23 : "abc"::length )); + m(cond ? (() -> 23) : ("abc"::length) ); + m(( cond ? () -> 23 : cond ? ("abc"::length) : (() -> 23) )); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific11.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8034223 + * @summary Return type Object is not more specific than return type String + * @compile MostSpecific11.java + */ +class MostSpecific11 { + + interface I { Object run(); } + interface J { String run(); } + + void m(I arg) {} + void m(J arg) {} + + void test() { + m(() -> { throw new RuntimeException(); }); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific12.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,38 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8034223 + * @summary Most-specific testing with inference variables in function parameter types + * @compile/fail/ref=MostSpecific12.out -XDrawDiagnostics MostSpecific12.java + */ +class MostSpecific12 { + + interface I<T> { void take(T arg1, String arg2); } + interface J<T> { void take(String arg1, T arg2); } + interface K { void take(String arg1, String arg2); } + + <T> void m1(I<T> arg) {} + void m1(K arg) {} + + <T> void m2(J<T> arg) {} + <T> void m2(K arg) {} + + <T> void m3(I<T> arg) {} + <T> void m3(J<T> arg) {} + + void test() { + m1((String s1, String s2) -> {}); // ok + m2((String s1, String s2) -> {}); // ok + m3((String s1, String s2) -> {}); // error + + m1(this::referencedMethod); // ok + m2(this::referencedMethod); // ok + m3(this::referencedMethod); // error + + m1(String::compareTo); // ok + m2(String::compareTo); // ok + m3(String::compareTo); // error + } + + void referencedMethod(String s1, String s2) {} + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific12.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,4 @@ +MostSpecific12.java:25:9: compiler.err.ref.ambiguous: m3, kindname.method, <T>m3(MostSpecific12.I<T>), MostSpecific12, kindname.method, <T>m3(MostSpecific12.J<T>), MostSpecific12 +MostSpecific12.java:29:9: compiler.err.ref.ambiguous: m3, kindname.method, <T>m3(MostSpecific12.I<T>), MostSpecific12, kindname.method, <T>m3(MostSpecific12.J<T>), MostSpecific12 +MostSpecific12.java:33:9: compiler.err.ref.ambiguous: m3, kindname.method, <T>m3(MostSpecific12.I<T>), MostSpecific12, kindname.method, <T>m3(MostSpecific12.J<T>), MostSpecific12 +3 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific13.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,21 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8034223 + * @summary Most-specific testing with inference variables in function parameter types + * @compile/fail/ref=MostSpecific13.out -XDrawDiagnostics MostSpecific13.java + */ +class MostSpecific13 { + + interface UnaryOp<T> { T apply(T arg); } + interface IntegerToNumber { Number apply(Integer arg); } + + <T> void m(UnaryOp<T> f) {} + void m(IntegerToNumber f) {} + + void test() { + m((Integer i) -> i); // error + m(this::id); // error + } + + Integer id(Integer arg) { return arg; } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific13.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,3 @@ +MostSpecific13.java:16:9: compiler.err.ref.ambiguous: m, kindname.method, <T>m(MostSpecific13.UnaryOp<T>), MostSpecific13, kindname.method, m(MostSpecific13.IntegerToNumber), MostSpecific13 +MostSpecific13.java:17:9: compiler.err.ref.ambiguous: m, kindname.method, <T>m(MostSpecific13.UnaryOp<T>), MostSpecific13, kindname.method, m(MostSpecific13.IntegerToNumber), MostSpecific13 +2 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific14.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,33 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8034223 + * @summary Most-specific testing for nested functional interface types + * @compile/fail/ref=MostSpecific14.out -XDrawDiagnostics MostSpecific14.java + */ +class MostSpecific14 { + interface ToNumber { Number get(); } + interface ToToNumber { ToNumber get(); } + interface Factory<T> { T get(); } + + void m1(Factory<Factory<Object>> f) {} + void m1(ToToNumber f) {} + + void m2(Factory<Factory<Number>> f) {} + void m2(ToToNumber f) {} + + void m3(Factory<Factory<Integer>> f) {} + void m3(ToToNumber f) {} + + + void test() { + m1(() -> () -> 23); // ok: choose ToToNumber + m2(() -> () -> 23); // error: ambiguous + m3(() -> () -> 23); // ok: choose Factory<Factory<Integer>> + + m1(() -> this::getInteger); // ok: choose ToToNumber + m2(() -> this::getInteger); // error: ambiguous + m3(() -> this::getInteger); // ok: choose Factory<Factory<Integer>> + } + + Integer getInteger() { return 23; } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/MostSpecific14.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,3 @@ +MostSpecific14.java:24:9: compiler.err.ref.ambiguous: m2, kindname.method, m2(MostSpecific14.Factory<MostSpecific14.Factory<java.lang.Number>>), MostSpecific14, kindname.method, m2(MostSpecific14.ToToNumber), MostSpecific14 +MostSpecific14.java:28:9: compiler.err.ref.ambiguous: m2, kindname.method, m2(MostSpecific14.Factory<MostSpecific14.Factory<java.lang.Number>>), MostSpecific14, kindname.method, m2(MostSpecific14.ToToNumber), MostSpecific14 +2 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/SingleLocalTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8029852 + * @summary Bad code generated (VerifyError) when lambda instantiates + * enclosing local class and has captured variables + */ +public class SingleLocalTest { + interface F {void f();} + + static F f; + + public static void main(String[] args) { + StringBuffer sb = new StringBuffer(); + class Local1 { + public Local1() { + f = () -> new Local1(); + sb.append("1"); + } + } + new Local1(); + f.f(); + String s = sb.toString(); + if (!s.equals("11")) { + throw new AssertionError("Expected '11' got '" + s + "'"); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/T8037935/LambdaWithBinOpConstRefToConstString.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8037935 + * @summary Javac: final local String var referenced in binary/unary op in lambda produces code that does not verify + * @run main LambdaWithBinOpConstRefToConstString + */ + +interface MyFI { + void accept(); +} + +public class LambdaWithBinOpConstRefToConstString { + public static void main(String[] args) { + final String CONSTANT_STRING_VALUE = "mwmwm"; + + MyFI consumeStrings = () -> { + System.out.println(" local constant: " + CONSTANT_STRING_VALUE); + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/T8038420/LambdaIncrement.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8038420 + * @summary Lambda returning post-increment generates wrong code + * @run main LambdaIncrement + */ + +public class LambdaIncrement { + + interface IntegerOp { Integer apply(Integer arg); } + + private static void assertNotIncremented(IntegerOp lmb, String label) { + int result = lmb.apply(3); + if (result != 3) { + throw new AssertionError("Post-increment failure. Expected 3, got: " + + result + " " + label); + } + } + + public static void main(String... args) throws Exception { + assertNotIncremented(x -> x++, "PostIncExpr"); + assertNotIncremented(x -> { return x++; }, "PostIncReturn"); + assertNotIncremented(x -> { int y = x; return y++; }, "PostIncLocal"); + assertNotIncremented(x -> { Integer y = x; return y++; }, "PostIncLocalBox"); + assertNotIncremented(x -> { int y = x; return y; }, "HASINIT"); + } +}
--- a/test/tools/javac/lambda/TargetType01.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/TargetType01.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,6 +42,10 @@ static String M(F_S_S f){ return null; } static { - M(x1 -> { return M( x2 -> { return x1 + x2; });}); //ambiguous + M(x1 -> { + return M( x2 -> { + return x1 + x2; + }); + }); //ambiguous } }
--- a/test/tools/javac/lambda/TargetType01.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/TargetType01.out Thu May 29 13:46:36 2014 -0700 @@ -1,3 +1,3 @@ TargetType01.java:45:9: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 -TargetType01.java:45:26: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 +TargetType01.java:46:20: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 2 errors
--- a/test/tools/javac/lambda/TargetType02.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/TargetType02.java Thu May 29 13:46:36 2014 -0700 @@ -1,31 +1,9 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 8003280 + * @test /nodynamiccopyright/ + * @bug 8003280 8029718 * @summary Add lambda tests * check overload resolution and target type inference w.r.t. generic methods + * Should always use lambda body structure to disambiguate overload resolution * @author Maurizio Cimadamore * @compile/fail/ref=TargetType02.out -XDrawDiagnostics TargetType02.java */ @@ -47,9 +25,18 @@ static <Z extends Number> void call3(S1<Z> s) { } static <Z extends String> void call3(S2<Z> s) { } + static <Z extends Number> Z call4(S1<Z> s) { return null; } + static <Z extends String> Z call4(S2<Z> s) { return null; } + void test() { call1(i -> { toString(); return i; }); call2(i -> { toString(); return i; }); call3(i -> { toString(); return i; }); + call3(i -> { + toString(); + return call4(j -> { + return j; + }); + }); } }
--- a/test/tools/javac/lambda/TargetType02.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/TargetType02.out Thu May 29 13:46:36 2014 -0700 @@ -1,3 +1,5 @@ -TargetType02.java:52:14: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.String) -TargetType02.java:53:9: compiler.err.ref.ambiguous: call3, kindname.method, <Z>call3(TargetType02.S1<Z>), TargetType02, kindname.method, <Z>call3(TargetType02.S2<Z>), TargetType02 -2 errors +TargetType02.java:33:14: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.String) +TargetType02.java:34:9: compiler.err.ref.ambiguous: call3, kindname.method, <Z>call3(TargetType02.S1<Z>), TargetType02, kindname.method, <Z>call3(TargetType02.S2<Z>), TargetType02 +TargetType02.java:35:9: compiler.err.ref.ambiguous: call3, kindname.method, <Z>call3(TargetType02.S1<Z>), TargetType02, kindname.method, <Z>call3(TargetType02.S2<Z>), TargetType02 +TargetType02.java:37:20: compiler.err.ref.ambiguous: call4, kindname.method, <Z>call4(TargetType02.S1<Z>), TargetType02, kindname.method, <Z>call4(TargetType02.S2<Z>), TargetType02 +4 errors
--- a/test/tools/javac/lambda/TargetType16.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/TargetType16.java Thu May 29 13:46:36 2014 -0700 @@ -1,9 +1,9 @@ /* * @test /nodynamiccopyright/ - * @bug 8003280 + * @bug 8003280 8034223 * @summary Add lambda tests * Check void-compatibility in strict vs. loose conversion contexts - * @compile/fail/ref=TargetType16.out -XDrawDiagnostics TargetType16.java + * @compile TargetType16.java */ class TargetType16 { @@ -20,6 +20,6 @@ static <T> void m(SAM2<T> s2) { } public static void main(String[] args) { - m(() -> { throw new AssertionError(); }); //ambiguous + m(() -> { throw new AssertionError(); }); // prefer SAM2 } }
--- a/test/tools/javac/lambda/TargetType16.out Mon May 19 22:00:11 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -TargetType16.java:23:9: compiler.err.ref.ambiguous: m, kindname.method, m(TargetType16.SAM1), TargetType16, kindname.method, <T>m(TargetType16.SAM2<T>), TargetType16 -1 error
--- a/test/tools/javac/lambda/TargetType21.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/TargetType21.out Thu May 29 13:46:36 2014 -0700 @@ -1,7 +1,5 @@ TargetType21.java:28:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 -TargetType21.java:31:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 -TargetType21.java:32:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 -TargetType21.java:32:13: compiler.err.cant.apply.symbol: kindname.method, call, TargetType21.SAM2, @888, kindname.class, TargetType21, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.unexpected.ret.val))) -TargetType21.java:33:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 -TargetType21.java:33:13: compiler.err.cant.apply.symbol: kindname.method, call, TargetType21.SAM2, @946, kindname.class, TargetType21, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.unexpected.ret.val))) -6 errors +TargetType21.java:32:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM1), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 +TargetType21.java:32:13: compiler.err.cant.apply.symbol: kindname.method, call, TargetType21.SAM1, @888, kindname.class, TargetType21, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.String))) +TargetType21.java:33:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM1), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 +4 errors
--- a/test/tools/javac/lambda/TargetType23.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/TargetType23.java Thu May 29 13:46:36 2014 -0700 @@ -31,7 +31,12 @@ void call(Sam2 s) { } <Z> void call(Sam3<Z> s) { } + void call2(Sam0 s) { } + void call2(Sam2 s) { } + <Z> void call2(Sam3<Z> s) { } + void test() { - call(()-> { throw new RuntimeException(); }); //ambiguous - both call(Sam0), call(Sam2), call(Sam3) match + call(()-> { throw new RuntimeException(); }); // ambiguous - call(Sam1) vs. call(Sam2) + call2(()-> { throw new RuntimeException(); }); // ok } }
--- a/test/tools/javac/lambda/TargetType23.out Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/TargetType23.out Thu May 29 13:46:36 2014 -0700 @@ -1,2 +1,2 @@ -TargetType23.java:35:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType23.Sam2), TargetType23, kindname.method, <Z>call(TargetType23.Sam3<Z>), TargetType23 +TargetType23.java:39:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType23.Sam1), TargetType23, kindname.method, call(TargetType23.Sam2), TargetType23 1 error
--- a/test/tools/javac/lambda/TargetType42.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/TargetType42.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,12 +31,18 @@ class TargetType42 { interface SAM<X, Y> { - Y f(X x); + Y f(X x); } <Z> void m(SAM<String, SAM<Z, Object>> s, Z z) { } void test(Object obj) { - m((x)->{ class Foo { }; return (x2)-> { new Foo(); return null; }; }, obj); + m((x)->{ + class Foo { } + return (x2)-> { + new Foo(); + return null; + }; + }, obj); } }
--- a/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/intersection/IntersectionTargetTypeTest.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 8002099 + * @bug 8002099 8010822 * @summary Add support for intersection types in cast expression */
--- a/test/tools/javac/lambda/lambdaExpression/LambdaTest1.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/lambdaExpression/LambdaTest1.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,7 +33,6 @@ import java.util.Collections; import java.util.List; import java.util.ArrayList; -import java.util.Date; public class LambdaTest1 {
--- a/test/tools/javac/lambda/lambdaExpression/SamConversionComboTest.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/lambdaExpression/SamConversionComboTest.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -209,7 +209,11 @@ final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); DiagnosticChecker dc = new DiagnosticChecker(); JavacTask ct = (JavacTask)tool.getTask(null, null, dc, null, null, Arrays.asList(samSourceFile, clientSourceFile)); - ct.analyze(); + try { + ct.analyze(); + } catch (Exception e) { + throw new AssertionError("failing SAM source file \n" + samSourceFile + "\n\n" + "failing client source file \n"+ clientSourceFile); + } if (dc.errorFound == checkSamConversion()) { throw new AssertionError(samSourceFile + "\n\n" + clientSourceFile); }
--- a/test/tools/javac/lambda/separate/Test.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/lambda/separate/Test.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,6 +23,7 @@ /* * @test + * @bug 8008708 * @compile Foo.java * @compile Test.java */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/environment/ProcessingEnvAnnoDiscovery.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8038080 + * @summary make sure that all declaration annotations are discovered + * by the processing environment + * @library /tools/javac/lib + * @build JavacTestingAbstractProcessor ProcessingEnvAnnoDiscovery + * @compile/process -processor ProcessingEnvAnnoDiscovery ProcessingEnvAnnoDiscovery.java + */ + +import java.lang.annotation.*; +import java.util.Set; +import javax.annotation.processing.*; +import javax.lang.model.element.*; + +import com.sun.tools.javac.util.*; + +@ProcessingEnvAnnoDiscovery.Anno1 +public class ProcessingEnvAnnoDiscovery<@ProcessingEnvAnnoDiscovery.Anno4 T> + extends JavacTestingAbstractProcessor { + private int round = 0; + + public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) { + if (round++ == 0) { + System.out.println(annos); + Assert.check(annos.contains(eltUtils.getTypeElement("java.lang.annotation.Target"))); + Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno1"))); + Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno2"))); + Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno3"))); + Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno4"))); + Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno5"))); + Assert.check(annos.size() == 6, "Found extra annotations"); //Anno1-5 + @Target + } + + return true; + } + + @Anno2 + public <@Anno5 K> K m(@Anno3 long foo) { + return null; + } + + @interface Anno1 {} + + @interface Anno2 {} + + @interface Anno3 {} + + @Target(ElementType.TYPE_PARAMETER) + @interface Anno4 {} + + @Target(ElementType.TYPE_PARAMETER) + @interface Anno5 {} + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/environment/round/Anno.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.lang.annotation.*; +import static java.lang.annotation.RetentionPolicy.*; + +@Retention(RUNTIME) +public @interface Anno {}
--- a/test/tools/javac/processing/environment/round/BuriedAnnotations.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/processing/environment/round/BuriedAnnotations.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ */ /** - * Class to hold annotations for ElementsAnnotatedWithTest. + * Class to hold annotations for TestElementsAnnotatedWith. */ @AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings",
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/environment/round/ErroneousAnnotations.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,12 @@ +/** /nodynamiccopyright/ + * Class to hold annotations for TestElementsAnnotatedWith. + */ + +@AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings", + expectedSize=0, + names={}) +@Undefined +public class ErroneousAnnotations { + @Undefined + private void foo() {return;} +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/environment/round/ErroneousAnnotations.out Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,3 @@ +ErroneousAnnotations.java:8:2: compiler.err.cant.resolve: kindname.class, Undefined, , +ErroneousAnnotations.java:10:6: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, ErroneousAnnotations, null) +2 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/environment/round/ParameterAnnotations.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Class to hold annotations for ElementsAnnotatedWithTest. + */ + +@AnnotatedElementInfo(annotationName="Anno", + expectedSize=1, + names={"annotatedParameter"}) +public class ParameterAnnotations { + private void foo(@Anno Object annotatedParameter) {} +}
--- a/test/tools/javac/processing/environment/round/Part1.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/processing/environment/round/Part1.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ */ /** - * Class to hold annotations for ElementsAnnotatedWithTest. + * Class to hold annotations for TestElementsAnnotatedWith. */ @AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings",
--- a/test/tools/javac/processing/environment/round/Part2.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/processing/environment/round/Part2.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ */ /** - * Class to hold annotations for ElementsAnnotatedWithTest. + * Class to hold annotations for TestElementsAnnotatedWith. */ @SuppressWarnings("") public class Part2 {
--- a/test/tools/javac/processing/environment/round/SurfaceAnnotations.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/processing/environment/round/SurfaceAnnotations.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ */ /** - * Class to hold annotations for ElementsAnnotatedWithTest. + * Class to hold annotations for TestElementsAnnotatedWith. */ @AnnotatedElementInfo(annotationName="java.lang.SuppressWarnings",
--- a/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854 + * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854 8030049 8038080 * @summary Tests that getElementsAnnotatedWith works properly. * @author Joseph D. Darcy * @library /tools/javac/lib @@ -31,29 +31,26 @@ * @compile TestElementsAnnotatedWith.java * @compile InheritedAnnotation.java * @compile TpAnno.java + * @compile Anno.java * @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java * @compile -processor TestElementsAnnotatedWith -proc:only BuriedAnnotations.java * @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java * @compile -processor TestElementsAnnotatedWith -proc:only C2.java * @compile -processor TestElementsAnnotatedWith -proc:only Foo.java * @compile -processor TestElementsAnnotatedWith -proc:only TypeParameterAnnotations.java + * @compile -processor TestElementsAnnotatedWith -proc:only ParameterAnnotations.java + * @compile/fail/ref=ErroneousAnnotations.out -processor TestElementsAnnotatedWith -proc:only -XDrawDiagnostics ErroneousAnnotations.java * @compile Foo.java * @compile/process -processor TestElementsAnnotatedWith -proc:only Foo */ import java.lang.annotation.Annotation; -import java.io.*; import java.util.Collections; import java.util.Set; import java.util.HashSet; -import java.util.List; -import java.util.ArrayList; import java.util.Arrays; import javax.annotation.processing.*; -import javax.tools.*; -import javax.lang.model.SourceVersion; import javax.lang.model.element.*; -import javax.lang.model.util.*; import static javax.lang.model.util.ElementFilter.*; /** @@ -96,7 +93,8 @@ roundEnvironment. getElementsAnnotatedWith(elements.getTypeElement(annotatedElementInfo.annotationName())); - System.err.println("Results: " + resultsMeta); + if (!resultsMeta.isEmpty()) + System.err.println("Results: " + resultsMeta); if (resultsMeta.size() != annotatedElementInfo.expectedSize()) { failed = true;
--- a/test/tools/javac/processing/environment/round/TypeParameterAnnotations.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/processing/environment/round/TypeParameterAnnotations.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ */ /** - * Class to hold annotations for ElementsAnnotatedWithTest. + * Class to hold annotations for TestElementsAnnotatedWith. */ @AnnotatedElementInfo(annotationName="TpAnno",
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/resolve/AmbiguityErrorTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8041663 + */ + +public class AmbiguityErrorTest { + + public interface A { } + + public interface B extends A { } + + public interface C { + A m(B strategy); + } + + public interface D { + A m(A strategy); + A m(B strategy); + } + + public interface T1 extends C, D { } + public interface T2 extends D, C { } + + int count; + + class T1Impl implements T1, T2 { + public A m(B strategy) { + count++; + return null; + } + public A m(A strategy) { + throw new AssertionError("Should not get here."); + } + } + + public static void main(String... args) { + new AmbiguityErrorTest().test(); + } + + void test() { + T1 t1 = new T1Impl(); + T2 t2 = new T1Impl(); + final B b = new B() { }; + t1.m(b); + t2.m(b); + + if (count != 2) { + throw new IllegalStateException("Did not call the methods properly"); + } + } + +}
--- a/test/tools/javac/resolve/ResolveHarness.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/resolve/ResolveHarness.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,8 +23,8 @@ /* * @test - * @bug 7098660 - * @summary Write better overload resolution/inference tests + * @bug 7098660 8014649 8034223 + * @summary Test harness for overload resolution/inference tests * @library /tools/javac/lib * @build JavacTestingAbstractProcessor ResolveHarness * @run main ResolveHarness
--- a/test/tools/javac/resolve/tests/PrimitiveOverReferenceVarargsAmbiguous.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/resolve/tests/PrimitiveOverReferenceVarargsAmbiguous.java Thu May 29 13:46:36 2014 -0700 @@ -23,44 +23,44 @@ @TraceResolve(keys={"compiler.err.ref.ambiguous"}) class PrimitiveOverReferenceVarargsAmbiguous { - @Candidate(applicable=Phase.VARARGS, mostSpecific=true) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_byte(byte... b) {} - @Candidate(applicable=Phase.VARARGS) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_byte(Byte... b) {} - @Candidate(applicable=Phase.VARARGS, mostSpecific=true) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_short(short... s) {} - @Candidate(applicable=Phase.VARARGS) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_short(Short... s) {} - @Candidate(applicable=Phase.VARARGS, mostSpecific=true) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_int(int... i) {} - @Candidate(applicable=Phase.VARARGS) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_int(Integer... i) {} - @Candidate(applicable=Phase.VARARGS, mostSpecific=true) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_long(long... l) {} - @Candidate(applicable=Phase.VARARGS) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_long(Long... l) {} - @Candidate(applicable=Phase.VARARGS, mostSpecific=true) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_float(float... f) {} - @Candidate(applicable=Phase.VARARGS) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_float(Float... f) {} - @Candidate(applicable=Phase.VARARGS, mostSpecific=true) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_double(double... d) {} - @Candidate(applicable=Phase.VARARGS) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_double(Double... d) {} - @Candidate(applicable=Phase.VARARGS, mostSpecific=true) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_char(char... c) {} - @Candidate(applicable=Phase.VARARGS) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_char(Character... c) {} - @Candidate(applicable=Phase.VARARGS, mostSpecific=true) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_bool(boolean... z) {} - @Candidate(applicable=Phase.VARARGS) + @Candidate(applicable=Phase.VARARGS, mostSpecific=false) static void m_bool(Boolean... z) {} {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/resolve/tests/PrimitiveVsReferenceSamePhase.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +@TraceResolve(keys={"compiler.err.ref.ambiguous"}) +class PrimitiveVsReferenceSamePhase { + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_byte(Byte b1, byte b2) {} + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_byte(Byte b1, Byte b2) {} + + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_short(Short s1, short s2) {} + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_short(Short s1, Short s2) {} + + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_int(Integer i1, int i2) {} + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_int(Integer i1, Integer i2) {} + + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_long(Long l1, long l2) {} + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_long(Long l1, Long l2) {} + + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_float(Float f1, float f2) {} + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_float(Float f1, Float f2) {} + + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_double(Double d1, double d2) {} + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_double(Double d1, Double d2) {} + + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_char(Character c1, char c2) {} + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_char(Character c1, Character c2) {} + + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_bool(Boolean z1, boolean z2) {} + @Candidate(applicable=Phase.BOX, mostSpecific=false) + static void m_bool(Boolean z1, Boolean z2) {} + + { + m_byte((byte)0, (byte)0); + m_short((short)0, (short)0); + m_int(0, 0); + m_long(0L, 0L); + m_float(0.0f, 0.0f); + m_double(0.0, 0.0); + m_char('?', '?'); + m_bool(false, false); + } +}
--- a/test/tools/javac/scope/7046348/EagerInterfaceCompletionTest.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javac/scope/7046348/EagerInterfaceCompletionTest.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -181,7 +181,7 @@ case FIELD: case SUPER: return true; case METHOD: return hk != HierarchyKind.INTERFACE || ak == ActionKind.REMOVE_B || - (hk == HierarchyKind.INTERFACE && ak == ActionKind.REMOVE_A && vk == VersionKind.LAMBDA); + (hk == HierarchyKind.INTERFACE && ak == ActionKind.REMOVE_A); default: throw new AssertionError("Unexpected test kind " + this); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/varargs/MethodHandleCrash.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8034048 + * @summary javac crash with method references plus lambda plus var args + * @author govereau + * + * @compile MethodHandleCrash.java + */ +public interface MethodHandleCrash { + static<T> void functional(T... input) { + java.util.function.Consumer<T> c = MethodHandleCrash::functional; + } +}
--- a/test/tools/javadoc/parser/7091528/T7091528.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javadoc/parser/7091528/T7091528.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,8 +23,8 @@ /** * @test - * @bug 7091528 - * @summary javadoc attempts to parse .class files + * @bug 7091528 8029145 8037484 + * @summary ensures javadoc parses unique source files and ignores all class files * @compile p/C1.java p/q/C2.java * @run main T7091528 */ @@ -37,17 +37,32 @@ public static void main(String... args) { new T7091528().run(); } - void run() { File testSrc = new File(System.getProperty("test.src")); File testClasses = new File(System.getProperty("test.classes")); - String[] args = { - "-d", ".", + // 7091528, tests if class files are being ignored + runTest("-d", ".", "-sourcepath", testClasses + File.pathSeparator + testSrc, "-subpackages", - "p" - }; + "p"); + // 8029145, tests if unique source files are parsed + runTest("-d", ".", + "-sourcepath", testSrc.getAbsolutePath(), + "-subpackages", + "p:p.q"); + File testPkgDir = new File(testSrc, "p"); + File testFile = new File(testPkgDir, "C3.java"); + runTest("-d", ".", + "-sourcepath", testSrc.getAbsolutePath(), + testFile.getAbsolutePath(), + "p"); + runTest("-d", ".", + "-classpath", testSrc.getAbsolutePath(), + testFile.getAbsolutePath(), + "p"); + } + void runTest(String... args) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); String doclet = com.sun.tools.doclets.standard.Standard.class.getName(); @@ -60,7 +75,7 @@ } if (rc != 0) - System.err.println("javadoc failed: exit code = " + rc); + throw new Error("javadoc failed: exit code = " + rc); if (out.matches("(?s).*p/[^ ]+\\.class.*")) throw new Error("reading .class files");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javadoc/parser/7091528/p/C3.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +/** This is class C3, and no package for me please */ +public class C3 {} +
--- a/test/tools/javap/InvalidOptions.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javap/InvalidOptions.java Thu May 29 13:46:36 2014 -0700 @@ -24,7 +24,7 @@ /* * @test * @bug 8027411 - * @summary test invalid options -h and -b + * @summary test an invalid option */ import java.io.*; @@ -39,7 +39,6 @@ } void run() throws Exception { - test(2, "-h", "Error: -h is no longer available - use the javah program"); test(2, "-b", "Error: unknown option: -b", "Usage: javap <options> <classes>", "use -help for a list of possible options");
--- a/test/tools/javap/MethodParameters.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javap/MethodParameters.java Thu May 29 13:46:36 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,24 +44,24 @@ static final String Init0_expected = (" Foo();\n" + " descriptor: ()V\n" + - " flags: \n" + + " flags:\n" + " Code:\n" + " stack=1, locals=1, args_size=1\n" + - " 0: aload_0 \n" + + " 0: aload_0\n" + " 1: invokespecial #1 // Method java/lang/Object.\"<init>\":()V\n" + - " 4: return \n" + + " 4: return\n" + " LineNumberTable:\n" + " line 2: 0").replaceAll(" +", " "); static final String Init1_expected = (" Foo(int);\n" + " descriptor: (I)V\n" + - " flags: \n" + + " flags:\n" + " Code:\n" + " stack=1, locals=2, args_size=2\n" + - " 0: aload_0 \n" + + " 0: aload_0\n" + " 1: invokespecial #1 // Method java/lang/Object.\"<init>\":()V\n" + - " 4: return \n" + + " 4: return\n" + " LineNumberTable:\n" + " line 3: 0\n" + " MethodParameters:\n" + @@ -71,25 +71,25 @@ static final String foo0_expected = (" void foo0();\n" + " descriptor: ()V\n" + - " flags: \n" + + " flags:\n" + " Code:\n" + " stack=0, locals=1, args_size=1\n" + - " 0: return \n" + + " 0: return\n" + " LineNumberTable:\n" + " line 4: 0").replaceAll(" +", " "); static final String foo2_expected = (" void foo2(int, int);\n" + " descriptor: (II)V\n" + - " flags: \n" + + " flags:\n" + " Code:\n" + " stack=0, locals=3, args_size=3\n" + - " 0: return \n" + + " 0: return\n" + " LineNumberTable:\n" + " line 5: 0\n" + " MethodParameters:\n" + " Name Flags\n" + - " j \n" + + " j\n" + " k").replaceAll(" +", " "); static final File classesdir = new File("methodparameters");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javap/StackMapTableTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8033930 8033913 + * @summary bad formatting of StackMapTable entries + */ + +import java.io.*; +import java.util.*; + +public class StackMapTableTest { + public static void main(String... args) throws Exception { + new StackMapTableTest().run(); + } + + void run() throws Exception { + String testClasses = System.getProperty("test.classes"); + String out = javap("-v", "-classpath", testClasses, A.class.getName()); + + String nl = System.getProperty("line.separator"); + out = out.replaceAll(nl, "\n"); + + if (out.contains("\n\n\n")) + error("double blank line found"); + + String expect = + " StackMapTable: number_of_entries = 2\n" + + " frame_type = 252 /* append */\n" + + " offset_delta = 2\n" + + " locals = [ int ]\n" + + " frame_type = 250 /* chop */\n" + + " offset_delta = 18\n"; + if (!out.contains(expect)) + error("expected text not found"); + + if (errors > 0) + throw new Exception(errors + " errors found"); + } + + String javap(String... args) throws Exception { + StringWriter sw = new StringWriter(); + PrintWriter out = new PrintWriter(sw); + int rc = com.sun.tools.javap.Main.run(args, out); + out.close(); + System.out.println(sw.toString()); + if (rc < 0) + throw new Exception("javap exited, rc=" + rc); + return sw.toString(); + } + + void error(String msg) { + System.out.println("Error: " + msg); + errors++; + } + + int errors; + + /** Simple test class to run through javap. */ + public class A { + public void a() { + for (int i = 0; i < 10; i++) { + System.out.println(i); + } + } + public void b() { + } + public void c() { + } + } +}
--- a/test/tools/javap/T4975569.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javap/T4975569.java Thu May 29 13:46:36 2014 -0700 @@ -40,10 +40,10 @@ verify("T4975569$Anno", "flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION"); verify("T4975569$E", "flags: ACC_FINAL, ACC_SUPER, ACC_ENUM"); verify("T4975569$S", "flags: ACC_BRIDGE, ACC_SYNTHETIC", - "InnerClasses:\n static"); + "InnerClasses:\n static"); verify("T4975569$V", "void m(java.lang.String...)", "flags: ACC_VARARGS"); - verify("T4975569$Prot", "InnerClasses:\n protected"); + verify("T4975569$Prot", "InnerClasses:\n protected"); //verify("T4975569$Priv", "InnerClasses"); if (errors > 0) throw new Error(errors + " found.");
--- a/test/tools/javap/T6868539.java Mon May 19 22:00:11 2014 -0700 +++ b/test/tools/javap/T6868539.java Thu May 29 13:46:36 2014 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 6868539 6868548 + * @bug 6868539 6868548 8035364 * @summary javap should use current names for constant pool entries, * remove spurious ';' from constant pool entries */ @@ -41,17 +41,17 @@ void run() { String output = javap("T6868539"); verify(output, "Utf8 +java/lang/String"); // 1: Utf8 - // 2: currently unused + // 2: currently unused verify(output, "Integer +123456"); // 3: Integer verify(output, "Float +123456.0f"); // 4: Float verify(output, "Long +123456l"); // 5: Long verify(output, "Double +123456.0d"); // 6: Double - verify(output, "Class +#[0-9]+ +// + T6868539"); // 7: Class - verify(output, "String +#[0-9]+ +// + not found"); // 8: String + verify(output, "Class +#[0-9]+ +// +T6868539"); // 7: Class + verify(output, "String +#[0-9]+ +// +not found"); // 8: String verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V"); - // 11: InterfaceMethodref + // 11: InterfaceMethodref verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V"); // 12: NameAndType if (errors > 0) throw new Error(errors + " found.");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javap/T8032814.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8032814 + * @summary LineNumberTable/LocalVariableTable tables duplication for the + * "-v -l" combination of options + * @compile -g T8032814.java + * @run main T8032814 + */ + +import java.io.*; +import java.util.*; + +public class T8032814 { + public static void main(String... args) throws Exception { + new T8032814().run(); + } + + void run() throws Exception { + Class<?> clazz = T8032814.class; + int count = clazz.getDeclaredConstructors().length + + clazz.getDeclaredMethods().length; + test(clazz, 0); + test(clazz, count, "-v"); + test(clazz, count, "-l"); + test(clazz, count, "-v", "-l"); + + if (errors > 0) + throw new Exception(errors + " errors occurred"); + } + + void test(Class<?> clazz, int expectedCount, String... opts) throws Exception { + System.err.println("test class " + clazz.getName() + " " + Arrays.asList(opts) + ": expect: " + expectedCount); + List<String> args = new ArrayList<String>(); + args.addAll(Arrays.asList(opts)); + args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes"))); + args.add(clazz.getName()); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw); + pw.close(); + String out = sw.toString(); + if (rc != 0) + throw new Exception("javap failed unexpectedly: rc=" + rc); + + int lntCount = 0, lvtCount = 0; + for (String line: out.split("[\r\n]+")) { + if (line.matches("^ *LineNumberTable:$")) + lntCount++; + if (line.matches("^ *LocalVariableTable:$")) + lvtCount++; + } + checkEqual("LineNumberTable", lntCount, expectedCount); + checkEqual("LocalVariableTable", lvtCount, expectedCount); + } + + void checkEqual(String attr, int found, int expect) { + if (found != expect) { + error("Unexpected number of occurrences of " + attr + "\n" + + "found: " + found + ", expected: " + expect); + } + } + + void error(String msg) { + System.err.println("Error: " + msg); + errors++; + } + + int errors = 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javap/T8032819.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8032819 + * @summary Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options + * @compile -g T8032819.java + * @run main T8032819 + */ + +import java.io.*; +import java.util.*; + +public class T8032819 { + static class Fields { + int f1; + int f2; + } + + public static void main(String... args) throws Exception { + new T8032819().run(); + } + + void run() throws Exception { + Class<?> clazz = Fields.class; + test(clazz); + test(clazz, "-c"); + test(clazz, "-l"); + test(clazz, "-l", "-c"); + test(clazz, "-v"); + test(clazz, "-v", "-c"); + test(clazz, "-v", "-l"); + test(clazz, "-v", "-l", "-c"); + + if (errors > 0) + throw new Exception(errors + " errors occurred"); + } + + static final String sep = System.getProperty("line.separator"); + static final String doubleBlankLine = sep + sep + sep; + + void test(Class<?> clazz, String... opts) throws Exception { + System.err.println("test " + Arrays.asList(opts)); + List<String> args = new ArrayList<String>(); + args.addAll(Arrays.asList(opts)); + args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes"))); + args.add(clazz.getName()); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw); + pw.close(); + String out = sw.toString(); + if (rc != 0) + throw new Exception("javap failed unexpectedly: rc=" + rc); + + int count = 0; + int i = out.indexOf(doubleBlankLine, 0); + while (i != -1) { + count++; + i = out.indexOf(doubleBlankLine, i + doubleBlankLine.length()); + } + + if (count > 0) + error(count + " double blank lines found"); + } + + void error(String msg) { + System.err.println("Error: " + msg); + errors++; + } + + int errors = 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javap/T8033180.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8033180 + * @summary Bad newline characters + */ + +import java.io.*; +import java.util.*; + +public class T8033180 { + + public static void main(String... args) throws Exception { + new T8033180().run(); + } + + void run() throws Exception { + // fast-track this case, because test cannot fail in this case + if (lineSep.equals(nl)) + return; + + test("-help"); + test("-version"); + + if (errors > 0) + throw new Exception(errors + " errors occurred"); + } + + static final String lineSep = System.getProperty("line.separator"); + static final String nl = "\n"; + + void test(String... opts) throws Exception { + System.err.println("test " + Arrays.asList(opts)); + List<String> args = new ArrayList<String>(); + args.addAll(Arrays.asList(opts)); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw); + pw.close(); + String out = sw.toString(); + if (rc != 0) + throw new Exception("javap failed unexpectedly: rc=" + rc); + + // remove all valid platform newline sequences + String out2 = out.replace(lineSep, ""); + + // count the remaining simple newline characters + int count = 0; + int i = out2.indexOf(nl, 0); + while (i != -1) { + count++; + i = out2.indexOf(nl, i + nl.length()); + } + + if (count > 0) + error(count + " newline characters found"); + } + + void error(String msg) { + System.err.println("Error: " + msg); + errors++; + } + + int errors = 0; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javap/T8033711.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8033711 + * @summary An exception is thrown if using the "-classpath" option with no arguments + */ + + +import java.io.*; + +public class T8033711 { + public static void main(String[] args) throws Exception { + new T8033711().run(); + } + + public void run() throws Exception { + String out = javap("-classpath"); + if (out.contains("IllegalArgumentException")) + throw new Exception("exception found in javap output"); + if (!out.contains("Error: invalid use of option")) + throw new Exception("expected error message not found in javap output"); + } + + String javap(String... args) { + StringWriter sw = new StringWriter(); + PrintWriter out = new PrintWriter(sw); + int rc = com.sun.tools.javap.Main.run(args, out); + out.close(); + System.out.println(sw.toString()); + System.out.println("javap exited, rc=" + rc); + return sw.toString(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javap/T8035104.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8035104 + * @summary reorder class file attributes in javap listing + */ + +import java.io.*; + +public class T8035104 { + public static void main(String[] args) throws Exception { + new T8035104().run(); + } + + public void run() throws Exception { + String[] lines = javap("-v", T8035104.class.getName()).split("[\r\n]+"); + int minor = -1; + int SourceFile = -1; + for (int i = 0; i < lines.length; i++) { + String line = lines[i]; + if (line.matches(" *minor version: [0-9.]+")) + minor = i; + if (line.matches(" *SourceFile: .+")) + SourceFile = i; + } + if (minor == -1) + throw new Exception("minor version not found"); + if (SourceFile == -1) + throw new Exception("SourceFile not found"); + if (SourceFile < minor) + throw new Exception("unexpected order of output"); + + System.out.println("output OK"); + } + + String javap(String... args) { + StringWriter sw = new StringWriter(); + PrintWriter out = new PrintWriter(sw); + int rc = com.sun.tools.javap.Main.run(args, out); + out.close(); + System.out.println(sw.toString()); + System.out.println("javap exited, rc=" + rc); + return sw.toString(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javap/WhitespaceTest.java Thu May 29 13:46:36 2014 -0700 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8033581 8033798 8033726 + * @summary Check whitespace in generated output + */ + +import java.io.*; +import java.util.*; + +public class WhitespaceTest { + public static void main(String... args) throws Exception { + new WhitespaceTest().run(); + } + + void run() throws Exception { + test("-v", "java.lang.String"); + test("-XDtab:1", "-v", "java.lang.String"); + + String testClasses = System.getProperty("test.classes"); + for (int i = 10; i < 40; i++) + test("-XDtab:" + i, "-v", "-classpath", testClasses, "WhitespaceTest$HelloWorld"); + + if (errors > 0) + throw new Exception(errors + " errors found"); + } + + void test(String... args) throws Exception { + // need to avoid "//" appearing as a constant in the constant pool + String slash = "/"; + String doubleSlash = slash + slash; + System.out.println("test: " + Arrays.asList(args)); + String out = javap(args); + for (String line: out.split("[\r\n]+")) { + if (line.endsWith(" ")) + error("line has trailing whitespace: " + line); + int comment = line.indexOf(doubleSlash); + if (comment > 0 && line.charAt(comment - 1) != ' ') + error("no space before comment: " + line); + if (line.matches(" +}")) + error("bad indentation: " + line); + } + } + + String javap(String... args) throws Exception { + StringWriter sw = new StringWriter(); + PrintWriter out = new PrintWriter(sw); + int rc = com.sun.tools.javap.Main.run(args, out); + out.close(); + System.out.println(sw.toString()); + if (rc < 0) + throw new Exception("javap exited, rc=" + rc); + return sw.toString(); + } + + void error(String msg) { + System.out.println("Error: " + msg); + errors++; + } + + int errors; + + // small class to test repeatedly with different tab values + static class HelloWorld { + public static void main(String... args) { + System.out.println("Hello World!"); + } + } +}