DZone
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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Culture and Methodologies
  3. Methodologies
  4. 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 · News
Like (6)
Save
Tweet
Share
9.65K 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

  • How To Best Use Java Records as DTOs in Spring Boot 3
  • Low-Code Development: The Future of Software Development
  • A Gentle Introduction to Kubernetes
  • Use AWS Controllers for Kubernetes To Deploy a Serverless Data Processing Solution With SQS, Lambda, and DynamoDB

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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: