-
Notifications
You must be signed in to change notification settings - Fork 356
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
Dataflow support for switch expressions #2373
Comments
Note that both Checker Framework and NullAway are missing support for switch expressions. But adding it to the later in a clean way would be much easier after having it in the former :) |
Thanks for reporting this issue! |
@msridhar for the more authoritative answer. AFAIK, we are focusing on Java 8 for our internal codebase (at Uber), and intend to remain compatible with that version for the foreseeable future. We are aiming to support Java 11 (uber/NullAway#259), and would probably not mind supporting Java 12 if we could. |
There is an issue tracking Java 12+ compatibility issues here: google/error-prone#1106 It looks like external contributors figured out fixes for most/all of the issues. I don't know if Google plans to merge any of those fixes. For what it's worth, as a user of Error Prone, when I upgraded my application to Java 12 I only had to disable one exception-throwing bug pattern. It even tolerated switch expressions, though IIRC its "unnecessary parentheses" bug pattern got confused and suggested removing the parens after the Also, in case it helps you all calculate the level of urgency / non-urgency of supporting switch expressions, I believe they are targeted to graduate out of preview in Java 13, which will be released 6 months from now in September, 2019. See: https://mail.openjdk.java.net/pipermail/amber-dev/2019-March/004126.html Edit: Switch expressions will still be a preview feature in Java 13, so they will probably not graduate out of preview until Java 14, which will be released in March, 2020. |
Core NullAway works fine (AFAIK) on Java 11. If supporting Java 12 is not a huge burden, and it doesn't break backward compatibility, we'd be happy to do it. I haven't thought carefully through what it takes to support the |
Update on this: adapting the CFG construction itself shouldn't be too hard, but it requires depending on the new Removing the So I would suggest that once typetools merges https://github.com/eisop/checker-framework and supports Java 9 - 12, we can look into backwards-incompatible support for Java 12 preview and Java 13+ in eisop. |
What breaks? Removing the overridden |
I think conditionally removing the As to a medium- to longer-term fix that maintains backward compatibility, the only way I see to do it is to use a pre-processor. raydac/java-comment-preprocessor seems to be maintained and has a Gradle plugin (example). They have an example showing how to conditionally include code for different Java versions here. I think it's worth experimenting with this tool as a way to get backward-compatible support, as this kind of thing will come up again for other new language features. @wmdietl thoughts? |
There is also the Manifold Preprocessor which is cool since it runs as a Javac plugin. But it doesn't put the preprocessor directives in comments, so the Manifold IDE plugin is required to prevent the IDE from showing syntax errors. |
@michaelhixson Our goal is to provide sound handling for all Java constructs. These assertion errors help us make sure that we correctly handle all possible ASTs. We could explore adding a flag that allows ignoring these issues. @msridhar Thanks for mentioning these two projects! After a quick look, I think I would prefer using java-comment-preprocessor, as it stays valid Java source (at least hopefully). |
@wmdietl Agreed re: keeping valid Java source. Even so, things will be a bit janky since the un-pre-processed source code won't compile and will likely show errors in an IDE. So probably the pre-processor will have to run before you can start hacking the code. But then the code might look modified according to Git? There really are some advantages to having a language with a built-in macro system... |
FWIW, Google Java Format just added support for JDK 14 constructs while maintaining backward compatibility through a bit of subclassing and clever reflection: google/google-java-format@4ddb914#diff-c96edae3736870de40b2ab8b0657014dR157-R169 From what I can tell, a single GJF jar built using JDK14 should still run fine all the way back to JDK 8. In order to format the JDK14 constructs, you need to be running GJF on JDK14, but that seems like a reasonable compromise. @wmdietl perhaps a similar approach could be used here, to avoid a pre-processor? |
@msridhar Thanks for the pointer! I'll take a look whether something like that would work. |
Yes that’s true. Even just having CFG construction being more compatible could be helpful for now, for other projects relying on dataflow. Fixing |
Seems like backward compat could be solved using a multi-release jar: https://openjdk.java.net/jeps/238 |
Yes, that may work. If you are interested in setting that up, we would gladly accept a pull request. Thanks! |
Cool I'll take a look this week to see what's involved. |
Great, thanks! |
Would you be willing to accept a PR that sets up the multi-release jar that just has a stub method for the |
That is OK. The multi-release jar is a rather different task than handling switch statements, so splitting them into different tasks makes sense. |
No, it was not. From the changelog: Partial support for JDK 16. You can run the Checker Framework on a JDK 16 JVM. |
Ok, thanks! I saw some changes to CFG construction in that PR related to switches, so I thought that maybe the CFGs at least would accurately represent switch expressions, even if full type checking is not yet supported. |
@msridhar The CFG construction treats switch statements a bit specially, and it also asserts that |
@mernst Has there been any movement on support for switch statements? |
We are working on it (currently evaluating a couple of different implementation strategies). Assistance is always welcome. |
As of release 3.20.0, The dataflow framework does not crash on switch expressions, but they are not analyzed. We are working on implementing the analysis. |
@smillst do you have an issue I could subscribe to, please? |
@fprochazka The issue that is mentioned immediately before your comment, #4982, adds support for switch expressions. It has already been merged. Release 3.20.0 will occur today. |
Now I understand, thanks! |
I am trying to use switch expressions, which is a new preview feature in Java 12. My application depends on NullAway, which is a compiler plugin that depends on the Checker Framework's dataflow library. When I try to compile code that includes a switch expression, NullAway propagates an exception thrown by the dataflow library, causing compilation to fail.
The problematic section of the source code being compiled looks like this:
The root cause of the error that is thrown is this, from the stack trace that NullAway prints:
That's pointing to this part of the dataflow library:
checker-framework/dataflow/src/main/java/org/checkerframework/dataflow/cfg/CFGBuilder.java
Lines 3382 to 3385 in 0e5541c
I originally filed this issue in NullAway's issue tracker, but the maintainer suggested that it was an upstream issue with the dataflow library so I should also file it here. I wanted to produce a test case that used dataflow directly without NullAway to share with you, but I couldn't figure out how.
The text was updated successfully, but these errors were encountered: