|
23 | 23 |
|
24 | 24 | /* |
25 | 25 | * @test |
26 | | - * @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050 8266436 8267221 8271928 8275097 8293897 8295401 8304671 8310326 8312093 8312204 8315452 8337976 8324859 8344706 |
| 26 | + * @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050 8266436 8267221 8271928 8275097 8293897 8295401 8304671 8310326 8312093 8312204 8315452 8337976 8324859 8344706 8351260 |
27 | 27 | * @summary tests error and diagnostics positions |
28 | 28 | * @author Jan Lahoda |
29 | 29 | * @modules jdk.compiler/com.sun.tools.javac.api |
@@ -3013,6 +3013,69 @@ public static boolean test2() { |
3013 | 3013 | }"""); |
3014 | 3014 | } |
3015 | 3015 |
|
| 3016 | + @Test //JDK-8351260 |
| 3017 | + void testVeryBrokenTypeWithAnnotations() throws IOException { |
| 3018 | + String code = """ |
| 3019 | + package tests; |
| 3020 | + class ListUtilsTest { |
| 3021 | + void test(List<@AlphaChars <@StringLength(int value = 5)String> s){ |
| 3022 | + } |
| 3023 | + } |
| 3024 | + """; |
| 3025 | + DiagnosticCollector<JavaFileObject> coll = |
| 3026 | + new DiagnosticCollector<>(); |
| 3027 | + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, |
| 3028 | + List.of("--enable-preview", "--source", SOURCE_VERSION), |
| 3029 | + null, Arrays.asList(new MyFileObject(code))); |
| 3030 | + CompilationUnitTree cut = ct.parse().iterator().next(); |
| 3031 | + |
| 3032 | + List<String> codes = new LinkedList<>(); |
| 3033 | + |
| 3034 | + for (Diagnostic<? extends JavaFileObject> d : coll.getDiagnostics()) { |
| 3035 | + codes.add(d.getLineNumber() + ":" + d.getColumnNumber() + ":" + d.getCode()); |
| 3036 | + } |
| 3037 | + |
| 3038 | + assertEquals("testVeryBrokenTypeWithAnnotations: " + codes, |
| 3039 | + List.of("3:32:compiler.err.illegal.start.of.type", |
| 3040 | + "3:51:compiler.err.dot.class.expected", |
| 3041 | + "3:57:compiler.err.expected2", |
| 3042 | + "3:60:compiler.err.expected2", |
| 3043 | + "3:61:compiler.err.expected2", |
| 3044 | + "3:67:compiler.err.not.stmt", |
| 3045 | + "3:70:compiler.err.expected", |
| 3046 | + "5:2:compiler.err.premature.eof"), |
| 3047 | + codes); |
| 3048 | + String result = toStringWithErrors(cut).replaceAll("\\R", "\n"); |
| 3049 | + System.out.println("RESULT\n" + result); |
| 3050 | + assertEquals("incorrect AST", |
| 3051 | + result, |
| 3052 | + """ |
| 3053 | + package tests; |
| 3054 | + \n\ |
| 3055 | + class ListUtilsTest { |
| 3056 | + \n\ |
| 3057 | + void test(List<@AlphaChars (ERROR: (ERROR)<@StringLength(int) value, (ERROR)> = 5), (ERROR: )> <error>) { |
| 3058 | + (ERROR: String > s); |
| 3059 | + { |
| 3060 | + } |
| 3061 | + } |
| 3062 | + }"""); |
| 3063 | + } |
| 3064 | + |
| 3065 | + @Test //JDK-8351260 |
| 3066 | + void testVeryBrokenTypeWithAnnotationsMinimal() throws IOException { |
| 3067 | + String code = """ |
| 3068 | + B<@C<@D(e f= |
| 3069 | + """; |
| 3070 | + DiagnosticCollector<JavaFileObject> coll = |
| 3071 | + new DiagnosticCollector<>(); |
| 3072 | + JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, |
| 3073 | + List.of("--enable-preview", "--source", SOURCE_VERSION), |
| 3074 | + null, Arrays.asList(new MyFileObject(code))); |
| 3075 | + //no exceptions: |
| 3076 | + ct.parse().iterator().next(); |
| 3077 | + } |
| 3078 | + |
3016 | 3079 | void run(String[] args) throws Exception { |
3017 | 3080 | int passed = 0, failed = 0; |
3018 | 3081 | final Pattern p = (args != null && args.length > 0) |
|
0 commit comments