-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8345614: Improve AnnotationFormatError message for duplicate annotation interfaces #22581
Conversation
👋 Welcome back scottmarlow! A progress list of the required criteria for merging this PR into |
@scottmarlow This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 82 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@liach) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
@scottmarlow The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java
Outdated
Show resolved
Hide resolved
f702182
to
7d5a9b6
Compare
@scottmarlow Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
Good point, sorry reviewers! |
Created a JBS issue https://bugs.openjdk.org/browse/JDK-8345614 for you. |
I'll force push once more to rename the commit to issue reference the ^ issue. Thank you @liach for creating that! |
7d5a9b6
to
725545e
Compare
@scottmarlow Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
725545e
to
636530f
Compare
@scottmarlow Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
…tionFormatError: Duplicate annotation for class" error Signed-off-by: Scott Marlow <smarlow@redhat.com>
636530f
to
32bbd46
Compare
@scottmarlow Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
@scottmarlow FYI you can have whatever number of commits with whatever name you like. OpenJDK bot generates a patch as if with Also, I think the issue title I have chosen is more descriptive than your current title. This specific case happens when there are duplicate annotation interfaces, and "container" isn't a good term for the class file that ships the annotation - it might be confused for repeatable annotation containers. |
Also, please enable GitHub actions here at https://github.com/scottmarlow/jdk/actions. You should see something like this: |
Makes sense, I'll update the title. I was trying to make the pre-check failure go away. |
Thanks, just updated ^ settings. |
I made a quick test for this, but you might not want to include it if you aim to backport this improvement to LTS releases as it uses the recently-finalized ClassFile API. /*
* Copyright (c) 2024, 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 8345614
* @summary Ensure message for duplicated annotations mention problematic class
* @library /test/lib
*/
import java.lang.annotation.AnnotationFormatError;
import java.lang.classfile.Annotation;
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassTransform;
import java.lang.classfile.FieldTransform;
import java.lang.classfile.MethodTransform;
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
import java.lang.classfile.attribute.RuntimeVisibleParameterAnnotationsAttribute;
import java.lang.constant.ClassDesc;
import java.nio.file.Path;
import java.util.List;
import jdk.test.lib.ByteCodeLoader;
public class DuplicateAnnotationsTest {
public static void main(String... args) throws Throwable {
ClassFile cf = ClassFile.of();
Path annoDuplicatedClass = Path.of(System.getProperty("test.classes")).resolve("AnnotationDuplicated.class");
Annotation annotation = Annotation.of(ClassDesc.of("java.lang.Deprecated"));
RuntimeVisibleAnnotationsAttribute rvaa = RuntimeVisibleAnnotationsAttribute.of(
List.of(annotation, annotation)
);
List<ClassTransform> transforms = List.of(
ClassTransform.endHandler(cob -> cob.with(rvaa)),
ClassTransform.transformingFields(FieldTransform.endHandler(fb -> fb.with(rvaa))),
ClassTransform.transformingMethods(MethodTransform.endHandler(mb -> mb.with(rvaa))),
ClassTransform.transformingMethods(MethodTransform.endHandler(mb -> mb.with(
RuntimeVisibleParameterAnnotationsAttribute.of(
List.of(List.of(annotation, annotation))
)
)))
);
var cm = cf.parse(annoDuplicatedClass);
for (var ct : transforms) {
var c = ByteCodeLoader.load("AnnotationDuplicated", cf.transformClass(cm, ct));
try {
c.getAnnotation(Deprecated.class);
var field = c.getDeclaredField("field");
field.getAnnotation(Deprecated.class);
var ctor = c.getDeclaredConstructor(int.class);
ctor.getAnnotation(Deprecated.class);
ctor.getParameters()[0].getAnnotation(Deprecated.class);
} catch (ReflectiveOperationException ex) {
throw new AssertionError(ex);
} catch (AnnotationFormatError err) {
var m = err.getMessage();
if (!m.contains("Deprecated") || !m.contains("AnnotationDuplicated"))
throw new AssertionError("Class not mentioned: " + m);
}
}
}
}
// Duplicate annotations on class, field, method (constructor), method parameter
class AnnotationDuplicated {
int field;
AnnotationDuplicated(int arg) {}
} Test confirms that error messages for duplicated annotations now mention both the duplicated annotation type and the type where the duplication happens. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally with the test I wrote; looks good.
I think we will merge this into JDK 25; please give it 24 hours for everyone to review after your latest push.
Once this is integrated, if you want to get this into JDK 24 (already forked from mainline, in RDP 1), you have to work with an OpenJDK author to file a late enhancement request https://openjdk.org/jeps/3#Late-Enhancement-Request-Process, and to backport to versions like 21, you also need an OpenJDK author to make a fix request https://openjdk.org/projects/jdk-updates/approval.html. For ease of backports, I do not require to add the test I used into the patch.
Excellent, I'm +1000 for adding your test, thank you very much for creating it! Can you create a pr against https://github.com/scottmarlow/jdk/tree/AnnotationParser_should_include_container_Duplicate_annotation_error or add the commit directly to this pr? |
@scottmarlow I plan to do a separate PR to add this test; so we get a clean commit that can be easily backported to 24 and existing LTS versions. |
Thanks, that sounds great as well! Thanks to you and others in the community that helped me with this! |
@scottmarlow If you want this patch committed, you need to issue the |
Thanks, will look at https://wiki.openjdk.org/display/SKARA/Pull+Request+Commands#PullRequestCommands-/integrate for guidance on what I need to do. In general, I'd like to see the change merged and back ported to LTS branches as well. |
I see now that I am simply supposed to mention integrate so here goes! /integrate |
@scottmarlow |
Nice. I will sponsor. /sponsor |
Going to push as commit 7aa0cbc.
Your commit was automatically rebased without conflicts. |
@liach @scottmarlow Pushed as commit 7aa0cbc. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
/backport jdk21u-dev |
@scottmarlow To use the |
I think you might have to cherry-pick the commit (or just prepare an identical patch), and name your PR |
/backport jdk21u-dev I think I can spawn a backport branch for you; you can create a PR out of that skara bot branch. |
@liach the backport was successfully created on the branch backport-liach-7aa0cbc9-master in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link: The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:
|
I opened https://github.com/openjdk/jdk21u-dev/compare/openjdk:master...openjdk-bots:backport-liach-7aa0cbc9-master?expand=1 but see message |
Unfortunate! I have created openjdk/jdk21u-dev#1329 for backport. |
/backport jdk24u This enhancement is too late for 24. Backporting to 24.0.1; this is a prerequisite for backporting to 21. |
@liach the backport was successfully created on the branch backport-liach-7aa0cbc9-master in my personal fork of openjdk/jdk24u. To create a pull request with this backport targeting openjdk/jdk24u:master, just click the following link: The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk24u:
|
I am getting the
Duplication annotation for class
error as mentioned in https://hibernate.atlassian.net/browse/HHH-18901. The current error message does not include the application class name (e.g. container) that the specified annotation is unexpectedly duplicated. This pull request is for including the class name that has the (duplicate) annotation.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22581/head:pull/22581
$ git checkout pull/22581
Update a local copy of the PR:
$ git checkout pull/22581
$ git pull https://git.openjdk.org/jdk.git pull/22581/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22581
View PR using the GUI difftool:
$ git pr show -t 22581
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22581.diff
Using Webrev
Link to Webrev Comment