IntelliJ IDEA 2017.2 EAP, with Smarter Control Flow Analysis
Earlier we mentioned that IntelliJ IDEA 2017.2 EAP features improved control flow analysis that infers the contracts of certain methods of String, Array, Collection and Map classes.
With today’s EAP build, this analysis becomes even smarter. If that sounds like something you might be interested in, read on and see how the new checks are going to work.
In our first example, Collection#isEmpty() returns true, which means that there are no characters in that string to iterate over, and IntelliJ IDEA is here to tell us that.
There’s more to this case, though. String#charAt(int index) will throw an exception when called on an empty string, or when index exceeds the value returned by String#length() method, so you can see that IntelliJ IDEA insight into that method comes handy in many cases.
The same intelligence applies to: String#isEmpty(), String#chatAt(int index), List$#get(int index), Set#contains(Object item), Map#containsKey(Object key), Map#containsValue(Object value), and many other methods.
Code analysis that reports nullability issues has also been improved, in particular when it comes to working with Collection and Map type parameters.
When you are trying to pass a collection that may contain null values where a collection with non-nullable items is expected, you get a warning that you probably shouldn’t:
Just the same way IntelliJ IDEA will make sure you’re safe when iterating over a collection that may contain null values:
When you are trying to check whether an expression is equal to one of several string literals, IntelliJ IDEA can help you to replace these checks with a Set#contains(Object key) call to make code more concise:
This new build has two improvements specifically aimed to help with migration to Java 9.
There is already an inspection that reports when you spin in a while loop on a non-volatile field, but now, if you’re using Java 9, IntelliJ IDEA suggests that you called Thread#onSpinWait() inside such a loop:
Doing so may significantly improve performance of your code.
Another Java 9 inspection suggests to use Set#of(String…items) where possible:
Last, but not least, you can pause file indexing if you need to free CPU to do other tasks, and then resume it again when it’s appropriate:
That’s it for now. We hope you’ll enjoy these improvements, and give the new build a try. You can download it right from the website, or update via Toolbox App. Patches for the in-product update should also be available if you’re using previous EAP build.
Develop with Pleasure!
Subscribe to Blog updates
Thanks, we've got you!
IntelliJ IDEA 2023.3 Release Candidate Is Out
IntelliJ IDEA 2023.3 Release Candidate is now available! You can get the latest build from our website, through the free Toolbox App, or via snaps for Ubuntu. To use this build, you need to have an active subscription to IntelliJ IDEA Ultimate. Download IntelliJ IDEA 2023.3 RC As we …
The What, Why, and How of JPA Buddy in IntelliJ IDEA
Master JPA entity management with JPA Buddy in IntelliJ IDEA! Our latest article shows you how to simplify your workflow and reduce boilerplate code.
IntelliJ IDEA 2023.3 Beta 3 Is Out!
IntelliJ IDEA 2023.3 Beta 3 is now available for download! You can get the latest build through our website, the free Toolbox App, from inside the IDE, or by using snaps for Ubuntu. Download IntelliJ IDEA Beta 3 This marks the last week before the release candidate is scheduled for delivery…
IntelliJ IDEA 2023.3 Beta 2 Is Out!
IntelliJ IDEA 2023.3 Beta 2 is out and ready for you to download! You can get the latest build from our website or via the free Toolbox App. You can also upgrade to 2023.3 Beta 2 from inside the IDE, or by using snaps for Ubuntu. Download IntelliJ IDEA Beta 2 While the team puts the finishi…