DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > IntelliJ IDEA 2017.2 EAP: Now With Smarter Control Flow Analysis

IntelliJ IDEA 2017.2 EAP: Now With Smarter Control Flow Analysis

Andrey Cheptsov user avatar by
Andrey Cheptsov
·
May. 20, 17 · Java Zone · News
Like (6)
Save
Tweet
9.40K Views

Join the DZone community and get the full member experience.

Join For Free

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, String#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 the 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.

intellij Enterprise architecture planning Flow (web browser)

Published at DZone with permission of Andrey Cheptsov, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Automation Testing vs. Manual Testing: What's the Difference?
  • Artificial Intelligence (AI) And Its Assistance in Medical Diagnosis
  • Event-Driven Microservices?
  • Data Mesh — Graduating Your Data to Next Level

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo