Loads of Small Improvements in IntelliJ IDEA 2017.2

Many of the features we’re going to talk about in this post have been mentioned elsewhere in this blog, but here we’re going to bring them all together and show how to use them.

Better Warnings

You’ll have seen before that IntelliJ IDEA can analyse your code and tell you if something isn’t needed, or perhaps doesn’t make sense.  IntelliJ IDEA 2017.2 has even better analysis in several areas.  The first we’re going to look at is Control Flow Analysis – IntelliJ IDEA can look at the logic in your code and tell you if certain cases just won’t occur.

For example, if a Collection or String is known to be empty, IntelliJ IDEA will tell you that certain types of operations will error or simply aren’t required, like iterating over an empty collection.

Warnings on empty collections

This applies to a number of methods on List, Map and Set, as well as String.

Other warnings on empty collections

There’s also improved analysis around nulls, particularly when passing Collections as parameters.  If, for example, you have a Collection that can contain nulls and you use it when calling a method that expects a Collection that does not contain nulls, you’ll get a warning.

Warnings on nulls

See the blog post on Smarter Flow Control Analysis for more details on the analysis of empty Collections/Strings and potential null problems.

Similarly, IntelliJ IDEA 2017.2 can also detect if a number is going to be out of range and warn you about this before your program errors at run time.

Warnings on unlikely number ranges

See the section on Smarter control flow analysis: number ranges in this blog post for more details.

The Reflection API has always had its risks, which is one of the reasons Java 9 modularity (JPMS) aims to provide better encapsulation. IntelliJ IDEA now has more help for working with reflection if you do need to use it, with coding assistance and added warnings.

Warnings on reflection methods

For more information see the Reflection API section in this blog post.

More Advanced Refactoring

As well as improved warnings that can spot bugs before running the code, IntelliJ IDEA 2017.2 also helps you to refactor existing code to simplify it or to make it more readable. For example, if you have a statement that contains a number of or clauses, this can be converted into a Set.contains statement – new values can then easily be added to the Set, rather than added to a long and difficult to read condition.

Replace with Set.contains

IntelliJ IDEA continues to add refactoring and suggestions to help you use the features in Java 8.  Now, if you extract a variable in a Stream operation, the IDE can suggest this is extracted as an additional map operation rather than adding an extra variable to the lambda expression.

Extract variable as map

Previously, you could extract functional parameters, letting you change a method to accept a lambda expression as a parameter.  Now you can also extract functional variables, so you reuse can some of these lambda expressions, or as a stepping stone to a larger refactoring, or maybe simply to create more readable code.

Extract functional variable

The last Java 8 refactoring to mention is the ability to reshape your code to use method references immediately. You may previously have used something like a combination of Extract Method and the “Lambda can be replaced with method reference” inspection in order to achieve this, now you can cut out a number of steps and extract to a method reference directly.

Refactor to method reference

Better Code Completion

Code completion has also been improved in IntelliJ IDEA 2017.2, smart completion can suggest much more than before. For example, if your code uses the classic builder pattern to create an instance (rather than calling new directly), smart completion will suggest using the builder when values of that type are required.

Suggested builder

When you select this option, the caret will automatically be placed into the correct position to set more values via the builder.

For more information see the Smart completion: builder classes section of this blog post.

Smart completion is also better at suggesting appropriate method chains in certain situations – if, for example, you frequently call a chain of methods this is now suggested on the first call to smart completion, whereas it was previously only suggested on the second call.

Chained method calls suggested

This feature relies on the project being indexed, and having been built by IntelliJ IDEA (not the Gradle compiler).

See the Smart Completion blog post for more information on this feature for chained method calls.

Notable Bug Fixes

Of course, releases aren’t just about new features, they’re also about improving the quality of the tool.  Here’s a summary of the most notable bug fixes that went into 2017.2.

  • The project window sometimes didn’t close on Windows IDEA-171010
  • The editor tabs limit didn’t work properly when set to 1 (2017.2.1) IDEA-173369
  • The project window didn’t properly restored in a maximised state on Windows IDEA-96168
  • When re-importing a Maven project, the IDE didn’t respect the language level IDEA-115977
  • The active editor/tool window tab was difficult to distinguish from a non-active IDEA-131683 & IDEA-103206
  • Per-monitor HiDPI scale-factor on Windows IDEA-164566
  • Automatically adjusted font size based on the HiDPI scale factor IDEA-151754
Posted in New Features | Tagged , , , | 1 Comment

Database Tools: What’s New in IntelliJ IDEA 2017.2

If you’re following our recent news, you already know that last week we released the new massive IntelliJ IDEA update, 2017.2. However, we didn’t mention its database tools much in the release announcement, so now it’s time to catch up on that, because there’s plenty of new features in that area.

Amazon Redshift and Microsoft Azure

These cloud database providers are now supported out of the box with dedicated drivers and their specific SQL syntaxes.

If you’re already using any of them via the standard SQL Server or PostgreSQL drivers, make sure that you migrate to the new dedicated drivers after upgrading to 2017.2.

Connecting to multiple PostgreSQL databases

You don’t need to create separate Data Sources for each of PostgreSQL databases you’re using anymore. Just select as many databases as needed when configuring a single PostgreSQL Data Source.

Evaluate expression

This feature, with which you could already be familiar if you’ve worked with Java code,, is now available for SQL expressions, too and allows you get a preview of a table, a column, or a query.

It can be invoked either via Alt+clicking an expression or selecting it and pressing Ctrl+Alt+F8 (Cmd+Alt+F8 for macOS). In case the expression you need to evaluate isn’t in the code, press Alt+F8, and you will get a dialog where you can enter it and see what it produces.

Transaction control

Auto-commit option in the Console has been replaced with its more advanced version, called Transaction Control, which is made available not only in the Console toolbar, but as the Data Source configuration option as well, and in addition to controlling the transaction mode (automatic or manual), also defines the transaction isolation level.

When this option is set to Manual, the toolbar will display the Commit and Rollback buttons.

Table DDL

The DDL tab is removed from the Table Editor, and now if you want to see DDL, call Edit Source by clicking the its icon in the Database tool window toolbar, or via the Ctrl+B (Cmd+B for macOS).

By the way, DataGrip 2017.2 release that will include all these features is just around the corner, so stay tuned for updates!

The IntelliJ IDEA and DataGrip teams,
The Drive to Develop!

Posted in New Features | Tagged , , , , , | 4 Comments

Support for JUnit 5 M4 in IntelliJ IDEA 2017.2

IntelliJ IDEA provides support for the upcoming JUnit 5 release. JUnit has pretty much been the standard for Java unit testing for years, and the latest version brings the library right up to date, making use of Java 8 features and bringing in ways of testing that are familiar if you’ve been using other frameworks like Spock.  IntelliJ IDEA 2017.2 adds support for some of these features, to make the experience of testing code as painless and quick as possible.

JUnit 5 supports parameterized tests. These tests let you use the same basic structure of a test with a number of different inputs. This reduces duplication in your test code and also lets you easily add new cases without having to create entire new tests.

IntelliJ IDEA helps you with parameterized tests in a number of different ways,  Firstly, it reports “suspicious” use of both @Test and @ParameterizedTest annotations – you only need one of these in order to declare the method is a test.

Suspicious Annotations

If you press Alt + Enter on the highlighted @Test annotation, IntelliJ IDEA suggests removing this unnecessary annotation.

Remove Test Annotation suggestion

If you’re using the @ParameterizedTest annotation, you need to supply a source for the parameters, otherwise there are no tests to run.  IntelliJ IDEA warns you if you use the @ParameterizedTest annotation without an associated source (annotations like @MethodSource, @ValueSource etc.)

No sources supplied

If you’re using a source annotation, but it doesn’t match the expectations set by the  test method, you’ll also get a warning about this.  For example, if you use a @ValueSource that defines a series of ints as the input, but your test method takes a String parameter, IntelliJ IDEA will warn you that these types don’t match

Incorrect parameter types

Using a @MethodSource lets you choose a method that returns a Stream of values to use for parameters, and IntelliJ IDEA offers suggestions of suitable methods

Code completion for MethodSource

If you select a method that does not provide the right values for the test method’s arguments, you’ll get a warning about this as well. Here, we’ve given @MethodSource a method that returns a Stream of Strings, but because our test takes more than one argument we should have chosen a method that returns a Stream of Arguments.

Incorrect method source type

You’ll notice as well that when you provide a method to @MethodValue, this method is not marked as unused because IntelliJ IDEA recognises it’s used in the annotation.

No unused method

In addition to this support for parameterized tests, you also get warnings for using the @Test annotation with @RepeatedTest.

Help for repeated tests

IntelliJ IDEA 2017.2 makes it simple to use all the features in JUnit 5, so that it’s easier and quicker to write effective tests.

Posted in New Features | Tagged , , | 2 Comments

Debugger: Filtering Arrays & Collections in IntelliJ IDEA 2017.2

As usual, the newest version of IntelliJ IDEA contains updates to help you debug applications.  Given that we are working more and more with large data sets, IntelliJ IDEA 2017.2 has added the ability to filter arrays and collections in our variables or watches.

Breakpoint during debugging

In this example, I have a variable allWords that’s a list of Strings. This is a large list, so when I’m debugging my application I may want to look for specific values, or types of values, in this list.  I can do this by right-clicking on the list and selecting “filter”.

Select "filter" on a list or array

Then I can enter the criteria to filter. As you’d expect, IntelliJ IDEA offers code completion and suggestions here.

Code completion on the filter field

The debug window will now show me the subset of values in the list that match this criteria.

List filtered by start of word

If I right click on the filter, I can edit the filter to change the original criteria or add further filters

The filter can be changed

And I can easily remove the filter using the clear button.

Press clear to remove the filter

This feature also works on other Collection types, and arrays.  Here, we’ve added a watch expression that creates an array of random ints

An int array in watches

We can filter these values too

A filtered list of ints

This ability to filter the values in large collections like lists and arrays make it easier for us, as we’re debugging an application, to see which values are available, and particularly if one or more of them match some criteria we’re looking for.

Posted in New Features | Tagged , | 3 Comments

Webinar Recording: Why IntelliJ IDEA is the Premier IDE for Grails 3

Last Thursday we had a pleasure to host a live webinar with Jeff Scott Brown, the founder of the Grails framework. Jeff gave a comprehensive overview of the Grails 3 support in IntelliJ IDEA (both Community and Ultimate.)

In case you missed it, here’s a recording along with transcript of the Q&A session. Enjoy!

  • 5:19 Grails 2 vs Grails 3
  • 16:06 Demo of the Grails 3 support in IntelliJ IDEA Community Edition
  • 31:49 Intro into Grails 3 and IntelliJ IDEA Ultimate
  • 33:10 Demo of the Grails 3 support in IntelliJ IDEA Ultimate
  • 47:09 5 reasons to use IntelliJ IDEA for Grails

During the webinar Jeff and I answered a number of questions, so I am posting their transcriptions here.

Can you recommend any good books on Grails 3 development?

Does IntelliJ IDEA offer coding assistance for the GORM methods, such as .list(), .where(), .save(), etc?

GORM, among other Grails concepts, is fully supported by IntelliJ IDEA Ultimate. Community Edition doesn’t include this. If you want this support in Community Edition, make sure your classes implement the corresponding traits explicitly.

How to enable auto-reload in IntelliJ IDEA?

IntelliJ IDEA Ultimate supports auto-reload out of the box. In Community Edition, you have to manually add “-noverify“ to the VM options (to disable the bytecode verifier) in your Run Configuration.

What is the difference between GGTS and IntelliJ IDEA?

Currently the biggest difference is the dedicated support for Grails 3. AFAIK, Eclipse (GGTS) doesn’t support Grails 3.

How do I deploy a Grails 3 application to GlassFish?

Use the Grails command “grails war”, and then deploy it to GlassFish as a regular WAR file.

How to use Grails 3 along with GWT?

If we’re talking about simultaneously working with two separate applications in one IDE, then the best way to do that would be to use a multiple project Gradle build. If it’s about using GWT on top of Grails, check our the GWT Grails plugin.

Recommend a quick tutorial on GORM for a personal with SQL background

Check out the official GORM website.

Where can I get any help in migrating a Grails 2 project to Grails 3?

How is GORM MongoDB matured to use in production?

It’s really mature, but if you have any specific concerns, you can always contact the Grails team.

Does IntelliJ IDEA offer diagrams for Grails?

Yes, IntelliJ IDEA Ultimate offers diagrams for domain classes. To access diagrams, open the domain class, and switch to the Diagram tab in the bottom of the editor.

How can I use multiple datasources with Grails 3?

Check out the official documentation.

Would like us to do a webinar on a different topic / different speaker? Let us know in the comments!

Develop with Pleasure!

Posted in Webinars | Tagged | 1 Comment

IntelliJ IDEA 2017.2 is Here: Smart, Sleek, and Snappy

Great news, everyone!

2017.2, a new massive update for IntelliJ IDEA, is out and it’s packed full of new features and important bugfixes. Get a copy of this new release, and see for yourself, but before you do, it is worth spending a couple of minutes reading this summary for ideas on where to look.

  • Smarter code completion and control flow analysis
    • Smart Completion becomes aware of builder classes and suggests chains of method calls on its first call, and the chain suggestions are sorted according to how frequently symbols are used in the current project.
    • Control flow analysis has become much smarter and detects a wider array of problems, especially when booleans, strings, arrays, lists, and maps are involved; it also checks nullability issues when corresponding annotations are used on type parameters for collections and maps.
  • New inspections and refactorings
    • Inspections and quick-fixes: Replace with Set.of and Add Thread#onSpinWait() (both require Java 9), and Extract set from comparison chain.
    • Refactorings: Extract as Map Operation (for streams), Extract Functional Variable, and Extract Lambda to Method Reference
  • Java 9 module diagrams Learn more
  • Debugger: filtering arrays, collections, and maps
  • Spring Boot actuator endpoints
    • The Run tool window now provides the actuator endpoint information, like BeansHealth, and Mappings.
  • Kotlin 1.1.3 support
    • The editor can now display Parameter hints (introduced earlier for Java), along with Type hints, that is inferred type where it’s not explicitly set.
  • Groovy 2.5.0 support
  • VCS: reverting and rewording commits, formatting commit messages
  • User interface
    • Windows 10 native look and feel
    • Better HiDPI support for multiple display setup on Windows
    • Automatic font settings adjustment to match display resolution
  • JavaScript and TypeScript improvements
    • Editor: Parameter hints and Type info
    • Formatting: Rearrange Code
    • Refactorings: Move (across ES6 modules)
    • Frameworks: better support for React and AngularJS
    • CSS Modules support
    • Better Webpack support
    • Code coverage for Mocha
  • Performance
    • Arbitrary modules can now be marked as Unloaded to conserve CPU and memory resources when working on large projects.
    • You can suspend indexing and resume it at your convenience, for example, to save battery power.

For more details about the new and improved features (only the most notable of which are mentioned here), check out the release What’s New page.

Your feedback, as always, is very much appreciated in our issue tracker.

JetBrains recommends: to stay up-to-date with the latest releases, and, when needed, be able to safely switch between several IDE versions, install our
Toolbox App.

Your JetBrains Team

The Drive to Develop

Posted in New Features, Releases | Tagged | 85 Comments

Support for Java 9 in IntelliJ IDEA 2017.2

As Java 9 continues to evolve, so does IntelliJ IDEA’s support for it. This screencast shows the new features to support Java 9 development in the upcoming IntelliJ IDEA 2017.2 release.


In the rest of this blog post we’ll break down what’s in the video and talk about each feature.

As you’d expect, a lot of the improvements are to support the Java Platform Module System.  One of the new features to help developers getting up to speed with Jigsaw and Java modularity is the new Java Module Diagram.  This diagram shows the modules you’ve defined in your project in green; any automatic modules, (those modules that are dependencies on traditional jar files) in blue; and any JDK modules in yellow.

Java Module Diagram

You’ll notice there are two different types of lines in the diagram, the thick blue lines show “requires transitive“, the thinner black lines are standard “requires” dependencies.

These diagrams give a clear picture of which modules have been defined and which modules they depend upon, and can help you either to create a clean separation when creating a modular system, or simply visualise what’s going on with the new Java Platform Module System.

If you are working with Java 9 modules, you’ll see code completion and generation has been improved for the module-info.java file.  For a start, the generated module name more closely matches the IntelliJ IDEA module name.

Error in open module

Errors and warnings and their suggested fixes have also been improved. For example, if you try to use opens in a module that is already open , the error is clear and you can opt to either remove the opens statement or change the module so it’s no longer open.

Open module fixes

Duplicate opens or provides statements are detected and can be deleted or merged.

Duplicate opens statement

You can also use find usages on a module name to locate other places that use this module, including JDK modules that use it.

Find module usages

And, of course, you can refactor module-info files, for example using rename.

Project Jigsaw has a wider impact than just allowing you to create your own modules.  Modularity impacts the visibility of packages, so classes that were previously accessible may not be any more. This even includes reflection.  IntelliJ IDEA’s inspections can help locate reflection code that tries to access modules that are not on the module path, and offers suggestions to fix the problem.

Reflection warnings

There are a few new inspections to help migrate code to Java 9. There’s a section under the Java language level migration aids inspections for Java 9.

New inspections

The first inspection highlights module-info files that require automatic modules – automatic modules are useful during migration to Java 9, but over time code should be migrated to use true modules. By default, this only highlights transitive dependencies, as this means your code is exposing automatic modules to other modules.

Using unmodifiableSet

The second inspection points out places where we can use the new Collections Factory Methods. For example, if we’re creating an unmodifiableSet, this verbose code can be enormously simplified in Java 9. We can also convert unmodifiableList to the new syntax too.

Using Set.of

There’s one final inspection to help us make use of new Java 9 features. If your code has while loops that wait for a particular value to change, they can be updated to add the new onSpinWait hint, which allows the runtime to potentially optimise this operation.

Suggestion to add onSpinWait

Finally, IntelliJ IDEA is also ready for the updates to Javadoc in Java 9.  Generated Javadoc is now searchable, letting developers search for classes, methods or keywords in the documentation.  To make the most use of this, you may want to add an index tag to your documentation to provide keywords to the search.

Posted in Releases | Tagged , , | 4 Comments

Git Questions – How and When do I Merge or Rebase?

Ever since Gary and I started the Git Questions video series, we’ve been asked to talk about merging.  We’re also frequently asked about rebasing – what is it, and when should I do it?

In this week’s video, we take a look at how to use IntelliJ IDEA to merge a branch back into the “main” development branch.  We also talk about rebasing – not only showing how to do it in the IDE, but what it means and when you should do it.

We don’t show how to deal with merge conflicts in this video, but they are discussed, and a more complete conflict-resolution video is definitely high on the TODO list.

Posted in Tips & Tricks | Tagged , | 12 Comments

Java Annotated Monthly – July 2017

The start of June brought the disappointing news that we’d have to wait longer for Java 9, so July and August news won’t be all about the big release.  However, there’s still plenty of Java 9 news, the usual handful of interesting Design and Architecture links, and this month a massive amount of Android and Kotlin news as we try to catch up with everything from Google I/O.


Continue reading

Posted in News & Events | Tagged , | Leave a comment

IntelliJ IDEA 2017.2 Public Preview

The last couple of months have been a lot of fun as we’ve been working on IntelliJ IDEA 2017.2 which is due out this summer. We appreciate the contributions from all EAP participants and the feedback they’ve shared on the new features. We reached a feature-freeze two weeks ago, and today, with roughly a month before the release, we’re happy to give you a detailed glimpse of what’s noteworthy in the upcoming IntelliJ IDEA 2017.2.

If you can’t wait, download the public preview build right away and try it on your own. Otherwise read on and learn about the major changes. Continue reading

Posted in EAP Releases, New Features | Tagged , | 14 Comments