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
On JDK 21, generated code should apply "this-escape" warning suppression #15619
Comments
If you can't fix the underlying problem, antlr/antlr4#4341 shows how to suppress the warnings on behalf of end-users. |
Thanks for your report.
I'd love to understand the rationale behind using this flag. The flag is so flawed, without being able to fine-tune every warning in the language, it is near useless. Why not use a third party tool that has the ability to fail builds more reliably, with more customisable behaviour? A similar issue is: #14865. The user's build fails for the same reason, and the source of the problem is a bug in the compiler (in my opinion): https://bugs.openjdk.org/browse/JDK-8305250 It is unlikely that Oracle will prioritise fixing this bug, given that it's probably rare and esoteric, and given that it's "just" a warning (ignorable), and not an error (show-stopper)
That issue describes something we're already doing. jOOQ classes start with: @SuppressWarnings({ "all", "unchecked", "rawtypes" }) But as the issue also says, Again, I fail to understand why I will obviously investigate this a bit more, but I'm not sure if anything can be done. This is a chicken-and-egg situation. The constructor should completely initialise the |
One workaround you might consider is to configure javac separately for the module containing jOOQ generated code, and turn off This is different in #14865, where the warning arises in client code, not jOOQ-generated code. |
Anyway, I'll take the opportunity to fix a few of these warnings that may arise from generated code, including:
Having said so, some warnings are (have always been) hard to avoid, so we don't have any integration tests to make sure they do not arise. As such, In a way, this is also true for the linked antlr issue. If the code is not in your control, then I wouldn't lint it |
So, I tried to reproduce this, but actually cannot. Our integration tests do not contain this warning with either JDK 20 or 21. How exactly did you configure your compiler? |
In case this helps, I'm also seeing this now that I'm eagerly trying out JDK 21 on my machine. Here's how the compiler has been configured in my case: options.compilerArgs = [
'-Xlint',
'-Xlint:-deprecation',
'-Xlint:-path',
'-Xlint:-processing',
'-Werror'
] I guess it could be the As you may guess from the above, we also tend to use
Now, enabling Perhaps you'd be better off by just emitting the Java bytecode right away instead of the |
Hmm, turns out this can actually be disabled by adding this to the /cc @cowwoc |
Great, thanks for digging this up, @perlun.
Just to be sure: I don't criticise the concept. I criticise the JDK's many non-suppressible warnings. But since this one can be suppressed, I guess the problem is "solved" for now. I'll still keep this issue open. In the past, I've also wondered if jOOQ-generated code could avoid passing around partially initialised objects, because that's obviously not very nice (even without linting). However, I couldn't find a solution yet, which would still allow for generated code to be initialised by the static initialiser of any class. |
The folks who have requested to make the indentation (2/4 spaces, tabs, etc.) configurable in the code generator will certainly like this idea 😅 |
works for fields / classes, might be an option for you @lukaseder to amend the corresponding declaration in jOOQ classes, too. FWIW |
So I heart there's a new API in Java 21 for that, so I wonder what you are waiting for, really… ;) |
Thanks for chiming in, @michael-simons. Interesting:
But the method is |
Anyway, so I'll look into this soon:
|
I guess I shouldn't give you any creative ideas, but another way to approach this could even be to wrap the (Speaking about compilation warnings, I found that even without |
jOOQ already ships with the |
Sorry for taking so long to reply:
My suggestion: Treat this like what it is: a warning. The compiler has identified a potential problem. So long as you review the code and it is safe then I would "sign off" on it by suppressing the warning. When I ran into these warnings in my own codebase I had two options: Give up on a class being immutable or suppress the warning. I opted for the latter. |
No one is going to generate bytecode here :)
Yes, I wrongly assumed that this is yet another non-suppressible warning by javac, but in fact, it is suppressible, so we're all good. |
Now I'm really disappointed with you Lukas... 😂 😜 |
Fixed in versions:
The fix just checks if the code generator is running on version 21+, independently of what jOOQ distribution is being used. |
Is there a reason to not just always emit the |
Someone with even stronger linting opinions will complain about a Unsupported @SuppressWarnings("this-escape") warning, I'm sure. |
I'm not sure I understand: i don't think |
There were a few issues related to
Why isn't it safe to do it the way I did? Among all the extreme edge cases, the case where someone uses an old JDK to generate code, but a newer one to run things seems quite far fetched. If anyone actually runs into this, they can open another bikeshed here on github, and I will make a 5317th configuration flag. (I should not have said anything about the implementation 😅) |
That's a real shame that there are broken IDE's that croak when it doesn't recognize a particular I'll have to work with our team to implement a workaround to get this all to work for our builds, since it appears we won't be able to depend on jOOQ codegen to just alway emit the suppression flag (since this will impact us, hence the reason I brought it up in the first place). |
|
We'll begrudgingly figure out a way to get this to work for us locally since it appears broken IDE's need to be appeased. |
It's a tradeoff. Someone's begrudging vs someone else's, and since these are bikesheds, the colour space of potential bikeshed begrudging is endless. I won't just generate an unsupported suppress warnings flag for everyone, just to make things work for a single user (nor could I backport that option easily, because jOOQ 3.18 didn't officially support JDK 21 yet). Today, this would appease your build (which is exotic, with different JDKs being in use for different purposes for reasons not yet stated). Tomorrow, such a hack would get in your way. While people are even more opinionated about IDEs than they are about linters and compiler warnings (I still don't understand why jOOQ-generated code is being linted in the first place), the Eclipse compiler is a very popular one also outside of the IDE. Visual Studio Code is using it, for example. This is not an IDE feature but a vendor specific compiler feature. But there. I have created a feature request where users can specify the output JDK version: In the future, such a flag might allow for overriding the behaviour of jOOQ's code generator when it has a Note, as a final workaround: It's also very easily possible to override the I hope any of the above appeases the begrudgement |
As to why JOOQ code is being linted... It's a mess to use different compilation flags for generated code than the main codebase: https://stackoverflow.com/a/39995250/14731 Also, the extra-paranoid among us want to receive notification when one of our dependencies introduces potential bugs and/or security vulnerabilities into the codebase. |
That looks simple to me... I was assuming you'd move jOOQ generated code to a separate module, but the option with two executions is also nice. You can also generate jOOQ code outside of
Nothing wrong with that. jOOQ has a few builds running just for that (separate builds though, as they don't require immediate action). I'd recommend a separate build for that purpose as well, just because, well, this kind of stuff quickly turns into busywork. Anyway, I think the issue is fixed. If there is enough reason to add more configuration, I can do that. Until then, there are tons of workarounds, including e.g. |
Expected behavior
Ability to compile the generated classes on JDK 21 without any warnings. Our company uses the
-Werror
javac option so warnings break our build.Actual behavior
When compiling, javac warns
possible 'this' escape before subclass is fully initialized
on this code:It repeats the warning once per
createField()
invocation in each class file.Steps to reproduce the problem
Code generation configuration:
jOOQ Version
3.18.6
Database product and version
Postgresql 15.4
Java Version
openjdk version "20.0.1" 2023-04-18
OS Version
Microsoft Windows [Version 10.0.19045.3448]
JDBC driver name and version (include name if unofficial driver)
org.postgresql:postgresql:42.6.0
The text was updated successfully, but these errors were encountered: