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

8254023: A module declaration is not allowed to be a target of an annotation that lacks an @Target meta-annotation #622

Closed
wants to merge 5 commits into from

Conversation

lgxbslgx
Copy link
Member

@lgxbslgx lgxbslgx commented Oct 13, 2020

Hi all,

The Java Language Specifications(JLS), from 8 to 13 included, state it as below:

If an annotation of type java.lang.annotation.Target is not present on the
declaration of an annotation type T , then T is applicable in all declaration contexts
except type parameter declarations, and in no type contexts.
These contexts are the syntactic locations where annotations were allowed in Java SE 7.

The JLS 14 and 15 state it as below:

If an annotation of type java.lang.annotation.Target is not present on the
declaration of an annotation type T , then T is applicable in all nine declaration
contexts and in all 16 type contexts.

This patch adds names.MODULE, names.TYPE_PARAMETER, names.TYPE_USE to com.sun.tools.javac.comp.Check.dfltTargetMeta to fix this issue.
Thank you for taking the time to review.

Best Regards.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8254023: A module declaration is not allowed to be a target of an annotation that lacks an @target meta-annotation

Download

$ git fetch https://git.openjdk.java.net/jdk pull/622/head:pull/622
$ git checkout pull/622

@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label Oct 13, 2020
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 13, 2020

Hi @lgxbslgx, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user lgxbslgx" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@lgxbslgx
Copy link
Member Author

/signed

@bridgekeeper bridgekeeper bot added the oca-verify Needs verification of OCA signatory status label Oct 13, 2020
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 13, 2020

Thank you! Please allow for up to two weeks to process your OCA, although it is usually done within one to two business days. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

@openjdk
Copy link

openjdk bot commented Oct 13, 2020

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

  • compiler

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 compiler compiler-dev@openjdk.org label Oct 13, 2020
@bridgekeeper bridgekeeper bot removed oca Needs verification of OCA signatory status oca-verify Needs verification of OCA signatory status labels Oct 14, 2020
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 14, 2020
@mlbridge
Copy link

mlbridge bot commented Oct 14, 2020

Webrevs

@jbf
Copy link
Member

jbf commented Oct 19, 2020

Hello,

Thank you for the contribution.

As you can see from the @target javadoc ( https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/annotation/Target.html ) there is some ambiguity here. I have rased a separate discussion on compiler-dev, depending on the outcome of that discussion this patch will need to be revised.

@lgxbslgx
Copy link
Member Author

Thanks for focusing on this patch. I will continue to follow the discussion and revise my patch based on the outcome of the discussion.

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 17, 2020

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

@lgxbslgx
Copy link
Member Author

lgxbslgx commented Dec 3, 2020

Short term (Java 16) it makes sense to fix https://bugs.openjdk.java.net/browse/JDK-8254023 given that both competing specs agree for this case, it is a small fix, and externally found.

For Java 17 we should align both specs and the reference implementation one way or another.

@jbf According to your comments, I revise my code to only fix JDK-8254023.
The rest of the work, ambiguity of the specifications, will be clarified and fixed in Java 17.
Thank you for taking the time to review.

@vicente-romero-oracle
Copy link
Contributor

the change looks good but I'm surprised that no other tests are failing and need changes, in particular tests like: test/langtools/tools/javac/annotations/repeatingAnnotations/combo/TargetAnnoCombo.java

@lgxbslgx
Copy link
Member Author

lgxbslgx commented Dec 8, 2020

@vicente-romero-oracle It is difficult to identify which test should be changed, because all the tests passed. As you said, the TargetAnnoCombo.java maybe need to be changed. I want to revise it now. Should I do it?

@vicente-romero-oracle
Copy link
Contributor

vicente-romero-oracle commented Dec 9, 2020

@vicente-romero-oracle It is difficult to identify which test should be changed, because all the tests passed. As you said, the TargetAnnoCombo.java maybe need to be changed. I want to revise it now. Should I do it?

sure please, I think that you should not only check that that test passes but also modify it, explicitly adding cases for the MODULE target. As a general comment this change is simple but the implications are not. I think the patch needs to add more tests. We also need to test that annotation processors can see annotations applied to modules, etc. We also need tests that check that target-less annotations, applied to modules are actually represented as such in the corresponding class file.

@jbf
Copy link
Member

jbf commented Dec 10, 2020

Hi,

I don't think TargetAnnoCombo should be updated, at least not for this fix. It is an old hard to understand test that predates modules.

It would be good to do further testing as Vicente writes. I suggest:

  1. A test that the module info compiles, you already have this.
  2. A test that the class file contains the bytes for the annotation might make sense. As Jon has pointed out in different review threads there is the toolbox, perhaps that could be of use? There are some examples of toolbox tests in jdk/test/langtools/tools/javac/modules though I don't have a good example of one that verifies the contents of the class file. Perhaps @vicente-romero-oracle can point to an example?
  3. There should already be tests that annotation processing can pick up annotations on module declarations, it looks like jdk/test/langtools/tools/javac/modules/AnnotationProcessing.java contains some of this. See if you can add a case with an annotation without @target.

@vicente-romero-oracle
Copy link
Contributor

Hi,

I don't think TargetAnnoCombo should be updated, at least not for this fix. It is an old hard to understand test that predates modules.

It would be good to do further testing as Vicente writes. I suggest:

1. A test that the module info compiles, you already have this.

2. A test that the class file contains the bytes for the annotation might make sense. As Jon has pointed out in different review threads there is the toolbox, perhaps that could be of use? There are some examples of toolbox tests in  `jdk/test/langtools/tools/javac/modules` though I don't have a good example of one that verifies the contents of the class file. Perhaps @vicente-romero-oracle can point to an example?

it is probably an overkill but method: testAnnos in test: test/langtools/tools/javac/records/RecordCompilationTests.java is an example applied to records that could be adapted to what we want here

@openjdk
Copy link

openjdk bot commented Dec 11, 2020

@lgxbslgx this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8254023
git fetch https://git.openjdk.java.net/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added merge-conflict Pull request has merge conflict with target branch and removed rfr Pull request is ready for review labels Dec 11, 2020
# Conflicts:
#	test/langtools/tools/javac/modules/AnnotationProcessing.java
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 11, 2020
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Dec 11, 2020
@lgxbslgx
Copy link
Member Author

I added two test cases. Thank you for taking the time to review.

@jbf
Copy link
Member

jbf commented Dec 15, 2020

Hi @lgxbslgx

This looks good to me. Since this is targeted to Java 16 we need to close this PR and open a new PR towards the JDK16 project and finish the review there, add a link back to this PR would also be neat. Can you do that?

cheers
/Joel

@openjdk
Copy link

openjdk bot commented Dec 15, 2020

@jbf Unknown command joel - for a list of valid commands use /help.

@lgxbslgx
Copy link
Member Author

@jbf I open a new PR in JDK 16. Please see openjdk/jdk16#34

@lgxbslgx
Copy link
Member Author

The later work will be completed in JDK 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org rfr Pull request is ready for review
3 participants