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

8268788: Annotations with lambda expressions can still cause AnnotationFormatError #4642

Closed

Conversation

fdesu
Copy link
Contributor

@fdesu fdesu commented Jun 30, 2021

Change #3294 helps to avoid AnnotaionFormatException in sun.reflect.annotation.AnnotationInvocationHandler.validateAnnotationMethods. While it fixes the case with e.g. Runnable that generates the synthetic method without parameters, validation still fails on synthetic methods that have parameters e.g. Function, BiFunction, etc.

This change removes the restriction on parameters count to be zero i.e. lambdas with parameters
would be skipped from validation.


Progress

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

Issue

  • JDK-8268788: Annotations with lambda expressions can still cause AnnotationFormatError

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4642/head:pull/4642
$ git checkout pull/4642

Update a local copy of the PR:
$ git checkout pull/4642
$ git pull https://git.openjdk.java.net/jdk pull/4642/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4642

View PR using the GUI difftool:
$ git pr show -t 4642

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4642.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 30, 2021

👋 Welcome back fdesu! 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 openjdk bot added the rfr Pull request is ready for review label Jun 30, 2021
@fdesu fdesu changed the title 8268788: Annotations with lambdas can still cause AnnotationFormatError 8268788: Annotations with lambda expressions can still cause AnnotationFormatError Jun 30, 2021
@openjdk
Copy link

openjdk bot commented Jun 30, 2021

@fdesu 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 Jun 30, 2021
@fdesu fdesu force-pushed the fix-annotations-with-non-argless-lambdas branch from 141d67a to bb08498 Compare June 30, 2021 20:11
@mlbridge
Copy link

mlbridge bot commented Jun 30, 2021

Webrevs

@fdesu
Copy link
Contributor Author

fdesu commented Jul 6, 2021

Hi, I would appreciate if anyone could take a look and let me know their opinion. Removing the parameters count == 0 condition from the sun.reflect.annotation.AnnotationInvocationHandler:507 fixes the problem, though I'm not entirely sure if it brings some risks with it.

@mlbridge
Copy link

mlbridge bot commented Jul 8, 2021

Mailing list message from Joe Darcy on core-libs-dev:

Hello,

I should be able to look at this within the next week or two; thanks,

-Joe

On 7/6/2021 1:22 AM, Sergei Ustimenko wrote:

1 similar comment
@mlbridge
Copy link

mlbridge bot commented Jul 8, 2021

Mailing list message from Joe Darcy on core-libs-dev:

Hello,

I should be able to look at this within the next week or two; thanks,

-Joe

On 7/6/2021 1:22 AM, Sergei Ustimenko wrote:

@mlbridge
Copy link

mlbridge bot commented Jul 8, 2021

Mailing list message from Sergei Ustimenko on core-libs-dev:

Hi Joe,

Thanks, I appreciate your feedback very much!

There was one more thing I wanted to discuss: there is something that
might be improved in the AnnotationInvocationHandler#validateAnnotationMethods
and I wanted to know if it makes sense to go ahead with the change.

There are `if` statements that set the variable called `valid` to false
in case validation fails. Later, depending on the value of the `valid`, an
instance of AnnotationFormatError being thrown. I was thinking if it makes sense
to simplify the validation loop (this is not the complete diff - just gives a
gist of what I mean):

@@ -493,10 +493,7 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
* Specification citations below are from JLS
* 9.6.1. Annotation Type Elements
*/
- boolean valid = true;
- Method currentMethod = null;
for(Method method : memberMethods) {
- currentMethod = method;
int modifiers = method.getModifiers();
// Skip over methods that may be a static initializer or
// similar construct. A static initializer may be used for
@@ -524,8 +521,7 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
method.isDefault() ||
method.getParameterCount() != 0 ||
method.getExceptionTypes().length != 0) {
- valid = false;
- break;
+ throw newAnnotationFormatErrorOf(method);
}

...
}
- if (valid)
- return;
- else
- throw new AnnotationFormatError("Malformed method on an annotation type: " +
- currentMethod.toString());
+ }
+
+ private static AnnotationFormatError newAnnotationFormatErrorOf(Method malformedMethod) {
+ return new AnnotationFormatError("Malformed method on an annotation type: " + malformedMethod);
}

What do you think? Does it make sense?

Thanks,
Sergei

??????? Original Message ???????

On Tuesday, July 6th, 2021 at 16:01, Joe Darcy <joe.darcy at oracle.com> wrote:

Hello,

I should be able to look at this within the next week or two; thanks,

-Joe

1 similar comment
@mlbridge
Copy link

mlbridge bot commented Jul 8, 2021

Mailing list message from Sergei Ustimenko on core-libs-dev:

Hi Joe,

Thanks, I appreciate your feedback very much!

There was one more thing I wanted to discuss: there is something that
might be improved in the AnnotationInvocationHandler#validateAnnotationMethods
and I wanted to know if it makes sense to go ahead with the change.

There are `if` statements that set the variable called `valid` to false
in case validation fails. Later, depending on the value of the `valid`, an
instance of AnnotationFormatError being thrown. I was thinking if it makes sense
to simplify the validation loop (this is not the complete diff - just gives a
gist of what I mean):

@@ -493,10 +493,7 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
* Specification citations below are from JLS
* 9.6.1. Annotation Type Elements
*/
- boolean valid = true;
- Method currentMethod = null;
for(Method method : memberMethods) {
- currentMethod = method;
int modifiers = method.getModifiers();
// Skip over methods that may be a static initializer or
// similar construct. A static initializer may be used for
@@ -524,8 +521,7 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
method.isDefault() ||
method.getParameterCount() != 0 ||
method.getExceptionTypes().length != 0) {
- valid = false;
- break;
+ throw newAnnotationFormatErrorOf(method);
}

...
}
- if (valid)
- return;
- else
- throw new AnnotationFormatError("Malformed method on an annotation type: " +
- currentMethod.toString());
+ }
+
+ private static AnnotationFormatError newAnnotationFormatErrorOf(Method malformedMethod) {
+ return new AnnotationFormatError("Malformed method on an annotation type: " + malformedMethod);
}

What do you think? Does it make sense?

Thanks,
Sergei

??????? Original Message ???????

On Tuesday, July 6th, 2021 at 16:01, Joe Darcy <joe.darcy at oracle.com> wrote:

Hello,

I should be able to look at this within the next week or two; thanks,

-Joe

@fdesu fdesu force-pushed the fix-annotations-with-non-argless-lambdas branch from bb08498 to fc04271 Compare July 19, 2021 10:19
@bridgekeeper
Copy link

bridgekeeper bot commented Aug 16, 2021

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

@fdesu fdesu force-pushed the fix-annotations-with-non-argless-lambdas branch from fc04271 to 1f5fd0a Compare August 16, 2021 13:51
@fdesu fdesu force-pushed the fix-annotations-with-non-argless-lambdas branch from d8bb4ce to 9cf2f0c Compare August 25, 2021 17:49
@fdesu
Copy link
Contributor Author

fdesu commented Aug 25, 2021

Hi,
I've reworked code in few places a bit. As we skip synthetic methods in couple
of places in AnnotationInvocationHandler:

  1. In equalsImpl while going method-by-method, comparing them
  2. In validateAnnotationMethods

(and as these two above work together to store methods in the memberMethods field) I though it makes sense to skip adding synthetic methods to the memberMethods field
altogether.

What do you think, does it makes sense? Thanks for taking a look!

@jddarcy
Copy link
Member

jddarcy commented Aug 27, 2021

Hello,

Thanks for the refined PR. Doing another round of review remain on my to-do list.

-Joe

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 24, 2021

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

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 22, 2021

@fdesu This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Oct 22, 2021
@jddarcy
Copy link
Member

jddarcy commented Oct 23, 2021

/open

@openjdk
Copy link

openjdk bot commented Oct 23, 2021

@jddarcy Only the pull request author can set the pull request state to "open"

@fdesu
Copy link
Contributor Author

fdesu commented Nov 18, 2021

/open

@openjdk openjdk bot reopened this Nov 18, 2021
@openjdk
Copy link

openjdk bot commented Nov 18, 2021

@fdesu This pull request is now open

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 16, 2021

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 13, 2022

@fdesu This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

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 rfr Pull request is ready for review
2 participants