Skip to content
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

scottmarlow
Copy link
Contributor

@scottmarlow scottmarlow commented Dec 5, 2024

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8345614: Improve AnnotationFormatError message for duplicate annotation interfaces (Enhancement - P4)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 5, 2024

👋 Welcome back scottmarlow! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 5, 2024

@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:

8345614: Improve AnnotationFormatError message for duplicate annotation interfaces

Reviewed-by: liach

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 master branch:

  • 166c127: 8345726: Update mx in RunTestPrebuiltSpec to reflect change in JDK-8345302
  • e821d59: 8345589: Simplify Windows definition of strtok_r
  • 153dc6d: 8345133: Test sun/security/tools/jarsigner/TsacertOptionTest.java failed: Warning found in stdout
  • d7ef3ac: 8345684: OperatingSystemMXBean.getSystemCpuLoad() throws NPE
  • 830173f: 8344068: Windows x86-64: Out of CodeBuffer space when generating final stubs
  • 69e664d: 8345632: [ASAN] memory leak in get_numbered_property_as_sorted_string function
  • 842b363: 8345698: Remove tier1_compiler_not_xcomp from github actions
  • 458979d: 8344611: Add missing classpath exception
  • 83ea013: 8345629: Remove expired flags in JDK 25
  • c517ffb: 8339910: RISC-V: crc32 intrinsic with carry-less multiplication
  • ... and 72 more: https://git.openjdk.org/jdk/compare/bd6d911cbe4b04221e52120cd0f8f04e219eca4d...master

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 /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk
Copy link

openjdk bot commented Dec 5, 2024

@scottmarlow The following label will be automatically applied to this pull request:

  • core-libs

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.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Dec 5, 2024
@scottmarlow scottmarlow force-pushed the AnnotationParser_should_include_container_Duplicate_annotation_error branch from f702182 to 7d5a9b6 Compare December 5, 2024 18:16
@openjdk
Copy link

openjdk bot commented Dec 5, 2024

@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
Copy link
Contributor Author

@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!

@liach
Copy link
Member

liach commented Dec 5, 2024

Created a JBS issue https://bugs.openjdk.org/browse/JDK-8345614 for you.

@scottmarlow
Copy link
Contributor Author

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!

@scottmarlow scottmarlow force-pushed the AnnotationParser_should_include_container_Duplicate_annotation_error branch from 7d5a9b6 to 725545e Compare December 5, 2024 19:06
@openjdk
Copy link

openjdk bot commented Dec 5, 2024

@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 scottmarlow force-pushed the AnnotationParser_should_include_container_Duplicate_annotation_error branch from 725545e to 636530f Compare December 5, 2024 19:09
@openjdk
Copy link

openjdk bot commented Dec 5, 2024

@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>
@scottmarlow scottmarlow force-pushed the AnnotationParser_should_include_container_Duplicate_annotation_error branch from 636530f to 32bbd46 Compare December 5, 2024 19:13
@openjdk
Copy link

openjdk bot commented Dec 5, 2024

@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 scottmarlow changed the title Include container in "java.lang.annotation.AnnotationFormatError: Duplicate annotation for class" error 8345614: Include container in "java.lang.annotation.AnnotationFormatError: Duplicate annotation for class" error Dec 5, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 5, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 5, 2024

Webrevs

@liach
Copy link
Member

liach commented Dec 5, 2024

@scottmarlow FYI you can have whatever number of commits with whatever name you like. OpenJDK bot generates a patch as if with git merge --squash and commits that patch with the correct issue title as the message, and with the correct commit email.

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.

@liach
Copy link
Member

liach commented Dec 5, 2024

Also, please enable GitHub actions here at https://github.com/scottmarlow/jdk/actions. You should see something like this:
image
The actions are the CI jobs that can compile the JDK and run some basic tier1 tests.

@scottmarlow
Copy link
Contributor Author

@scottmarlow FYI you can have whatever number of commits with whatever name you like. OpenJDK bot generates a patch as if with git merge --squash and commits that patch with the correct issue title as the message, and with the correct commit email.

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.

Makes sense, I'll update the title. I was trying to make the pre-check failure go away.

@scottmarlow scottmarlow changed the title 8345614: Include container in "java.lang.annotation.AnnotationFormatError: Duplicate annotation for class" error JDK-8345614: Improve AnnotationFormatError message for duplicate annotation interfaces Dec 5, 2024
@openjdk openjdk bot changed the title JDK-8345614: Improve AnnotationFormatError message for duplicate annotation interfaces 8345614: Improve AnnotationFormatError message for duplicate annotation interfaces Dec 5, 2024
@scottmarlow
Copy link
Contributor Author

Also, please enable GitHub actions here at https://github.com/scottmarlow/jdk/actions. You should see something like The actions are the CI jobs that can compile the JDK and run some basic tier1 tests.

Thanks, just updated ^ settings.

@liach
Copy link
Member

liach commented Dec 5, 2024

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.

Copy link
Member

@liach liach left a 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.

@scottmarlow
Copy link
Contributor Author

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.

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?

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 5, 2024
@liach
Copy link
Member

liach commented Dec 5, 2024

@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.

@scottmarlow
Copy link
Contributor Author

@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!

@liach
Copy link
Member

liach commented Dec 9, 2024

@scottmarlow If you want this patch committed, you need to issue the /integrate command yourself.

@scottmarlow
Copy link
Contributor Author

@scottmarlow If you want this patch committed, you need to issue the /integrate command yourself.

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.

@scottmarlow
Copy link
Contributor Author

I see now that I am simply supposed to mention integrate so here goes!

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Dec 9, 2024
@openjdk
Copy link

openjdk bot commented Dec 9, 2024

@scottmarlow
Your change (at version 32bbd46) is now ready to be sponsored by a Committer.

@liach
Copy link
Member

liach commented Dec 9, 2024

Nice. I will sponsor.

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 9, 2024

Going to push as commit 7aa0cbc.
Since your change was applied there have been 83 commits pushed to the master branch:

  • 35c0053: 8345405: Add JMH showing the regression in 8341649
  • 166c127: 8345726: Update mx in RunTestPrebuiltSpec to reflect change in JDK-8345302
  • e821d59: 8345589: Simplify Windows definition of strtok_r
  • 153dc6d: 8345133: Test sun/security/tools/jarsigner/TsacertOptionTest.java failed: Warning found in stdout
  • d7ef3ac: 8345684: OperatingSystemMXBean.getSystemCpuLoad() throws NPE
  • 830173f: 8344068: Windows x86-64: Out of CodeBuffer space when generating final stubs
  • 69e664d: 8345632: [ASAN] memory leak in get_numbered_property_as_sorted_string function
  • 842b363: 8345698: Remove tier1_compiler_not_xcomp from github actions
  • 458979d: 8344611: Add missing classpath exception
  • 83ea013: 8345629: Remove expired flags in JDK 25
  • ... and 73 more: https://git.openjdk.org/jdk/compare/bd6d911cbe4b04221e52120cd0f8f04e219eca4d...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 9, 2024
@openjdk openjdk bot closed this Dec 9, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Dec 9, 2024
@openjdk
Copy link

openjdk bot commented Dec 9, 2024

@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.

@scottmarlow
Copy link
Contributor Author

/backport jdk21u-dev

@openjdk
Copy link

openjdk bot commented Jan 14, 2025

@scottmarlow To use the /backport command, you need to be in the OpenJDK census and your GitHub account needs to be linked with your OpenJDK username (how to associate your GitHub account with your OpenJDK username).

@liach
Copy link
Member

liach commented Jan 14, 2025

I think you might have to cherry-pick the commit (or just prepare an identical patch), and name your PR Backport 7aa0cbc91d90493a3dae973cb8077cfa283c32b4 for jdk21u-dev.

@liach
Copy link
Member

liach commented Jan 14, 2025

/backport jdk21u-dev

I think I can spawn a backport branch for you; you can create a PR out of that skara bot branch.

@openjdk
Copy link

openjdk bot commented Jan 14, 2025

@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:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 7aa0cbc9 from the openjdk/jdk repository.

The commit being backported was authored by Scott Marlow on 9 Dec 2024 and was reviewed by Chen Liang.

Thanks!

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:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-liach-7aa0cbc9-master:backport-liach-7aa0cbc9-master
$ git checkout backport-liach-7aa0cbc9-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-liach-7aa0cbc9-master

⚠️ @liach You are not yet a collaborator in my fork openjdk-bots/jdk21u-dev. An invite will be sent out and you need to accept it before you can proceed.

@scottmarlow
Copy link
Contributor Author

/backport jdk21u-dev

I think I can spawn a backport branch for you; you can create a PR out of that skara bot branch.

I opened https://github.com/openjdk/jdk21u-dev/compare/openjdk:master...openjdk-bots:backport-liach-7aa0cbc9-master?expand=1 but see message Pull request creation failed. Validation failed: must be a collaborator

@liach
Copy link
Member

liach commented Jan 15, 2025

Unfortunate! I have created openjdk/jdk21u-dev#1329 for backport.

@liach
Copy link
Member

liach commented Jan 15, 2025

/backport jdk24u

This enhancement is too late for 24. Backporting to 24.0.1; this is a prerequisite for backporting to 21.

@openjdk
Copy link

openjdk bot commented Jan 15, 2025

@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:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 7aa0cbc9 from the openjdk/jdk repository.

The commit being backported was authored by Scott Marlow on 9 Dec 2024 and was reviewed by Chen Liang.

Thanks!

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:

$ git fetch https://github.com/openjdk-bots/jdk24u.git backport-liach-7aa0cbc9-master:backport-liach-7aa0cbc9-master
$ git checkout backport-liach-7aa0cbc9-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk24u.git backport-liach-7aa0cbc9-master

⚠️ @liach You are not yet a collaborator in my fork openjdk-bots/jdk24u. An invite will be sent out and you need to accept it before you can proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants