8339190: Parameter arrays that are capped during annotation processing report incorrect length#21663
8339190: Parameter arrays that are capped during annotation processing report incorrect length#21663nizarbenalla wants to merge 7 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back nbenalla! A progress list of the required criteria for merging this PR into |
|
@nizarbenalla 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 140 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. ➡️ To integrate this PR with the above commit message to the |
|
@nizarbenalla 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. |
| """; | ||
|
|
||
| FileWriter writer = new FileWriter(String.valueOf(out)); | ||
| BufferedWriter bufferedWriter = new BufferedWriter(writer); |
There was a problem hiding this comment.
This can be simplified to Files.newBufferedWriter.
Webrevs
|
- realized I need to change the condition in my for loop
|
I am sorry, but producing warnings is IMO a wrong solution. While the Java language does not impose limits, the classfile format does, and if we cannot generate a classfile that corresponds to the input Java file, javac should not produce anything and should finish up with a compile-time error. That is what is done for other limits as well. Like, for example, here: (Although this check for annotations may need to be done in |
|
I will update this PR and the CSR to fail if we detect an overflow, rather than warn users. Thanks Jan Though I am not sure why the check would need to be done when writing the classfile, why not do it earlier? |
|
|
||
| private void checkArraySize(List<JCExpression> tree) { | ||
| //check if attribute length exceeds maximum unsigned 16-bit value | ||
| if (!sigOnly && tree != null && (tree.size() >>> 16) > 0) { |
There was a problem hiding this comment.
Should we use (tree.size & ~0xFFFF) != 0? This is how classfile API checks the value compatibility, and I wonder how other places in javac does so.
There was a problem hiding this comment.
I was trying to chose between this and tree.size & ~0xFFFF, I think javac will sometimes check if an int is larger than 0xFFFF
There was a problem hiding this comment.
If you use & ~0xFFFF you must use != 0 as the mask includes the sign bit.
There was a problem hiding this comment.
I think the other checks are implemented as simple value > limit => error checks:
True, it may overflow, but if it would overflow once, it might overflow twice (back to positive numbers), so if/when that becomes a problem, we'd probably need something more complex. And it will be easier to find if the pattern is as close to the existing patterns as possible. So, I guess I would suggest to use a simple > ClassFile.MAX_ANNOTATIONS.
Some of the existing similar "limit" errors are basically only detectable when writing the classfile. So, for consistency, I think it would be good to do it at some place close to where the other errors are detected. In principle, the javac "frontend" should mostly care about JLS, and JLS is not imposing any limits. The backend, when writing, needs to care about JVMS, which imposes limits, and hence that's probably the correct place to report the error. |
generate error when param array is too large generate error closer to other limits, during code gen
|
I've updated the PR to now generate a compile-time error when the annotation array length exceeds the limit. I can make the test smaller if necessary. Or maybe expand it to include a negative test to check the code runs as intended. Will update the CSR next. |
vicente-romero-oracle
left a comment
There was a problem hiding this comment.
general comment. I wonder if we should add a predicate to com.sun.tools.javac.jvm.Target ala: Target::runtimeUseNestAccess() so that we don't generate this error for targets < 24, the rest looks good to me
I can easily add it if you or other Reviewers think it's a good idea. But it might not be worth it? The purpose of this change was to prevent generating classfiles that don't match the input files. I will bring it up in the CSR comment section. |
not sure tbh, probably not necessary |
vicente-romero-oracle
left a comment
There was a problem hiding this comment.
looks good
|
Passes tier 1-3, thanks all for the reviews on this. Here goes /integrate |
|
Going to push as commit 4244682.
Your commit was automatically rebased without conflicts. |
|
@nizarbenalla Pushed as commit 4244682. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Can I please get reviews for this change.
The regression test creates temporary files in
tmpdirto check that the warning is emitted correctly.I've also added the new warning to
example.not-yet.txtas the example would require a very large file.Here is the truncated result of running
javap -c -p -v(before the change) onClassAnnotationWithLength_65536_RUNTIME.classandClassAnnotationWithLength_65537_RUNTIME..classrespectively.After the change a compile-time error is thrown
TIA
Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21663/head:pull/21663$ git checkout pull/21663Update a local copy of the PR:
$ git checkout pull/21663$ git pull https://git.openjdk.org/jdk.git pull/21663/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21663View PR using the GUI difftool:
$ git pr show -t 21663Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21663.diff
Using Webrev
Link to Webrev Comment