-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8336942: Improve test coverage for class loading elements with annotations of different retentions #2955
base: master
Are you sure you want to change the base?
Conversation
…tions of different retentions Reviewed-by: vromero
👋 Welcome back cushon! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
This backport pull request has now been updated with issue from the original commit. |
Webrevs
|
@cushon This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Please keep this open for now |
|
I am not a Reviewer; I maintain This looks like a good change to have in 17. I tested it on While trying this out, I noticed a potential oddity regarding
to:
would cause a failure, but it does not. Am I missing something? I am testing with jtreg |
@fitzsim I tried with jtreg diff --git a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java b/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
index d4540107022..e22c3d132b9 100644
--- a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
+++ b/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
@@ -423,7 +423,7 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor {
// vary position of one annotated
// the three above with the corner case of the ambiguos decl + type anno added
- @Test(posn=0, annoType=TA.class, expect="1")
+ @Test(posn=0, annoType=TA.class, expect="33")
public @TA(1) int f1;
@Test(posn=0, annoType=TA.class, expect="11")
|
@cushon I should have included a patch for context; I was modifying the first of the two diff --git a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java b/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
index d4540107022..06bd32bcfbb 100644
--- a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
+++ b/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
@@ -535,7 +535,7 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor {
@Test(posn=1, annoType=TA.class, expect="23")
public Set<@TA(23) ? super Object> f9;
- @Test(posn=0, annoType=TA.class, expect="1")
+ @Test(posn=0, annoType=TA.class, expect="33")
@Test(posn=0, annoType=TD.class, expect="2")
public @TA(1) @TD(2) int f10;
I get:
but I would expect a failure. |
@fitzsim thanks for clarifying, and for the catch! I think that may be a long-standing bug in the test harness, it's grouping the annotations by position and if there are multiple annotations with the same position it only ends up looking at one of them. I can reproduce the expected failure with your change and something like the following. I think this issue with the test should be fixed at head, I will follow up on that. The motivation for originally adding the test in JDK-8336942 that's being backported here was that this example would cause a crash if the implementation failed to handle two annotations with different retentions at the same location, so there's some value in this even without the fix to the test harness. diff --git a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java b/test/langtools/tools/javac/processing/m
odel/type/BasicAnnoTests.java
index d4540107022..718b4aae95a 100644
--- a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
+++ b/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
@@ -139,7 +139,7 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor {
*/
class TestTypeScanner extends TypeScanner<Void, Void> {
Element elem;
- NavigableMap<Integer, AnnotationMirror> toBeFound;
+ NavigableMap<Integer, List<AnnotationMirror>> toBeFound;
int count = 0;
Set<TypeMirror> seen = new HashSet<>();
@@ -147,10 +147,10 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor {
super(types);
this.elem = elem;
- NavigableMap<Integer, AnnotationMirror> testByPos = new TreeMap<>();
+ NavigableMap<Integer, List<AnnotationMirror>> testByPos = new TreeMap<>();
for (AnnotationMirror test : tests) {
for (int pos : getPosn(test)) {
- testByPos.put(pos, test);
+ testByPos.computeIfAbsent(pos, ArrayList::new).add(test);
}
}
this.toBeFound = testByPos;
@@ -172,17 +172,18 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor {
out.println("scan " + count + ": " + t);
if (toBeFound.size() > 0) {
if (toBeFound.firstKey().equals(count)) {
- AnnotationMirror test = toBeFound.pollFirstEntry().getValue();
- String annoType = getAnnoType(test);
- AnnotationMirror anno = getAnnotation(t, annoType);
- if (anno == null) {
- error(elem, "annotation not found on " + count + ": " + t);
- } else {
- String v = getValue(anno, "value").toString();
- if (v.equals(getExpect(test))) {
- out.println("found " + anno + " as expected");
+ for (AnnotationMirror test : toBeFound.pollFirstEntry().getValue()) {
+ String annoType = getAnnoType(test);
+ AnnotationMirror anno = getAnnotation(t, annoType);
+ if (anno == null) {
+ error(elem, "annotation not found on " + count + ": " + t);
} else {
- error(elem, "Unexpected value: " + v + ", expected: " + getExpect(test));
+ String v = getValue(anno, "value").toString();
+ if (v.equals(getExpect(test))) {
+ out.println("found " + anno + " as expected");
+ } else {
+ error(elem, "Unexpected value: " + v + ", expected: " + getExpect(test));
+ }
}
}
} else if (count > toBeFound.firstKey()) { |
I filed https://bugs.openjdk.org/browse/JDK-8343882 for this |
Liam Miller-Cushon ***@***.***> writes:
I think this issue with the test should be fixed at head, I will
follow up on that.
I filed https://bugs.openjdk.org/browse/JDK-8343882 for this
Looks good, thank you. On Monday I will experiment on `jdk17u-dev` with your preliminary fix for the test harness.
|
Confirmed on my setup:
|
Independent of the harness fix, I would ideally like to be able replicate the crash you mention. I have not yet found a way to make the So far, I tried the new test on, and it succeeded on, |
…different retentions openjdk#2955
…different retentions openjdk#2955
Sorry for not providing more of this context up front. The crash was an interaction with the backport for JDK-8225377, which was previously backported to JDK 17 and backed out. The motivation for backporting this test change was to have coverage in-place if the backport ends up getting re-done (https://bugs.openjdk.org/browse/JDK-8341779). (It isn't certain if that backport will be re-done, if it is there will be additional discussion and a CSR first.) I created a draft PR with the changes to reproduce the crash here: #3038
The changes in the draft PR are
|
Thanks, that does clarify motivation. I do not see harm in merging this pull request in the meantime, even if the backport does not ultimately happen. From what I can tell (though I am not an expert in this area, and I did not step through the code) the new test lines may increase coverage of the existing |
This change improves annotation processing test coverage, see JDK-8336942. I resolved a trivial merge conflict with JDK-8323684, which added the
nameToAnnotation
map. The modified test passes.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk17u-dev.git pull/2955/head:pull/2955
$ git checkout pull/2955
Update a local copy of the PR:
$ git checkout pull/2955
$ git pull https://git.openjdk.org/jdk17u-dev.git pull/2955/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 2955
View PR using the GUI difftool:
$ git pr show -t 2955
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk17u-dev/pull/2955.diff
Using Webrev
Link to Webrev Comment