Community
Participate
Working Groups
BETA_JAVA8: The following program should trigger four errors. It triggers only two: // ------ public class X<T> { public void foo() { Object o = (X @Marker []) null; // Error here - Good. (ArrayTypeReference) o = (java.lang.String @Marker []) null; // Error here - Good. (ArrayQualifiedTypeReference) o = (X<String> @Marker []) null; // No error here - Bad. (ParameterizedSingleTypeReference) o = (java.util.List<String> @Marker []) null; // No error here, Bad. (ParameterizedQualifiedTypeReference) if (o == null) { return; } } } // ----
Created attachment 222168 [details] Proposed fix Patch with tests. All Java 8 tests pass and one of the existing test had to be adjusted. Running all tests now and will report once they complete.
(In reply to comment #1) > Running all tests now and will report once they complete. All existing tests pass too.
Two more issues found when reviewing this patch: - GrammarCoverageTests308#test019 is expecting wrong output. - The following program compiles fine when it should not: // ---- public class X { class Y { class Z {} } @M X.@M Y.@Unreported Z z = null; } @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE) @interface M { } The type annotation resolution code could use a good bit of reorganization. Patch will follow shortly.
Created attachment 222191 [details] Patch under consideration Jay, please take a look - this drastically simplifies annotation resolution,
One other problem the patch fixes is in: Object r = @Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null; We were not resolving the annotation ahead of Entry,
Jay, all tests pass. If you agree with the patch, please release. Note: At this point, the TypeUseBinding objects created are not hooked up either to the TypeReference or to the TypeBindig.
(In reply to comment #5) > One other problem the patch fixes is in: > > Object r = @Marker java. @Marker util.@Marker Map<@Marker String, @Marker > String>.@Marker Entry @Marker []) null; > > We were not resolving the annotation ahead of Entry, If the type reference in question has a problem, do we still want to resolve the annotation ahead of the type reference?
(In reply to comment #7) > If the type reference in question has a problem, do we still want to resolve > the annotation ahead of the type reference? I am OK with that. In general we should report as many errors as possible while avoiding reporting a cascade of secondary errors. By secondary errors I mean errors that would go away if some other already reported error is addressed. for example in: public class X { @Marker List<String> l; } We report two errors: - List cannot be resolved to a type - Marker cannot be resolved to a type Fixing the first by importing java.util.List does not resolve the latter and it is useful to report both. On the other hand it would not be acceptable to report that unknown type List cannot be parameterized with <String> What exactly do you have in mind ? Can you show me a test case ?
(In reply to comment #8) > What exactly do you have in mind ? Can you show me a test case ? Actually, it's the same test case quoted in comment #7. Your explanation is good. Sorry for the noise. Another question more out of curiosity: Object r = ( java.util.Map.@Unresolved Entry<?, ?>) null; We report a cannot-be-resolved error. The location where the annotation appears is disallowed but we are not reporting yet. Shouldn't we be reporting the disallowed error also?
(In reply to comment #9) > Another question more out of curiosity: > > Object r = ( java.util.Map.@Unresolved Entry<?, ?>) null; > > We report a cannot-be-resolved error. The location where the annotation > appears is disallowed but we are not reporting yet. Shouldn't we be > reporting the disallowed error also? It is legal to annotate Entry - why do you see it is illegal ?
(In reply to comment #10) > It is legal to annotate Entry - why do you see it is illegal ? Clearly, I am not thinking right! I meant this code, really: Object r = ( java.util.@MarkerAnnots Map.Entry<?, ?>) null; But we are reporting the correct error. So, there is no problem.
(In reply to comment #6) > Jay, all tests pass. If you agree with the patch, please release. Patch is good. Released it: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=108910be72e713e6e104fafacd635988e5383096