Skip to main content

Java development tools

Java™ 14 Support

Java 14 Java 14 is out and Eclipse JDT supports Java 14 for 4.15 via Marketplace.

The release notably includes the following Java 14 features:
JEP 361: Switch Expressions (Standard).
JEP 359: Records (Preview).
JEP 368: Text Blocks (Second Preview).
JEP 305: Pattern Matching for Instanceof (Preview).

Please note that preview option should be on for preview language features. For an informal introduction of the support, please refer to Java 14 Examples wiki.

Java Editor

Subword code completion Content Assist now supports subword patterns, similar to Eclipse Code Recommenders and other IDEs. For example, completing on addmouselistener proposes results like addMouseMoveListener and addMouseWheelListener.

This feature can be enabled using the Show subword matches option on the Java > Editor > Content Assist preference page.

Subtype code completion Content Assist will prioritize displaying constructor completions whose declaring type inherits from the expected return type within the completion context.

For example, completing on :

Queue<String> queue = new L

prioritizes constructors for LinkedBlockingQueue, LinkedBlockingDeQueue and LinkedList.

Option for non-blocking Java completion Code completion in the Java editor can now be run in a separate non-UI thread to prevent UI freezes in case of long computations. To enable this non-blocking computation, go to Preferences > Java > Editor > Content Assist > Advanced and check Do not block UI Thread while computing completion proposals preference. This option is currently disabled by default.

Non-blocking completion is useful when completion proposals are long to compute, as it allows you to type or use other parts of the IDE in the meantime.

Some completion participants may prevent this option from being effective (typically if the Java completion extension doesn't declare requiresUIThread="false"), so the UI thread may still be used even if this option is set.
The open Java file editors need to be closed and reopened for this option to be effective.

Quick fix to wrap Optional statements A quick fix has been added to wrap an Optional statement.

The options for a primitive statement are: Optional.empty() and Optional.of(). Type statements also have Optional.ofNullable().

Example for type objects:

Selecting Wrap with nullable Optional for type object results in:

Example for primitive:

Selecting Wrap with Optional for primitive results in:

Simplify functional interface instances A new clean up has been added that simplifies the lambda expression and the method reference syntax and is enabled only for Java 8 and higher.

The clean up removes parenthesis for a single untyped parameter, return statement for a single expression and brackets for a single statement. It replaces a lambda expression by a creation or a method reference when possible.

To select the clean up, invoke Source > Clean Up..., use a custom profile, and on the Configure... dialog select Simplify lambda expression and method reference syntax on the Code Style tab.

For the given code:

You get this after the clean up:

Directly use Map method Some map manipulations are unnecessarily verbose. The new cleanup option Operate on Maps directly calls methods on a map instead of calling the same methods on the key set or the values.

Beware! If you create Map implementations that don't follow the Map specification, this cleanup may break the behavior (a size() method that changes the values, an iterator that destroys the items...).

Preferences

For the given code:

Before

You get this after the clean up:

After

Uppercase for long literal suffix A new cleanup option Use uppercase for long literal suffix has been added. It will rewrite long literals like 101l with an uppercase L like 101L to avoid ambiguity.

Surround with "try-with-resources" block Corresponding to the quick fix which will surround a selection with a "try-with-resources" block, a new action has been added to the Surround With menu.

For example, selecting the lines as shown:

and right-clicking and selecting Surround With -> Try-with-resources Block

results in:

Quick fixes for module-info Javadoc Quick fixes have been added to fix the missing and duplicate @provides and @uses Javadoc tags in a module-info file.

No more spurious semicolon from import completion Almost 18 years ago, it was reported that completion for imports adds an unnecessary semicolon if one already exists (like when changing an existing import). Now this extra semicolon is no longer inserted.

Java Compiler

Warn when legacy code can taint null-checked values When using null-annotations for advanced null analysis, it is inherently tricky to combine your code with "legacy" code that has no null annotations and has not been blessed by such analysis.

Previously, Eclipse would only warn you when you obtain a dubious value from a legacy API, but it would keep silent in the opposite case: passing a value of an annotated type into legacy API. Still in specific situations this can cause a NullPointerException to be thrown in your null-checked code:

The console shows an exception thrown from within your checked main method (see the class-level @NonNullByDefault). It also shows the new warning, which Eclipse raises to alert you of this danger.

Hint: The shown code assumes the list names to have type List<@NonNull String>, but the legacy method Legacy.printNames() succeeds to taint this list by inserting a null element. This goes unnoticed because that method views the list has having type List<String>, with no nullness constraint on the type argument.

By default this problem is raised at level info, but the severity can be configured in the compiler settings:

Improved Resource leak analysis Resource leak analysis has been improved in several ways.

Most importantly, the analysis now consistently considers resources (=values of type AutoCloseable) which are acquired using a method call, where previously under some circumstances resource allocation got unnoticed if it was wrapped in a factory method, like in the following example:

makePrintWriter("/tmp/log.txt").printf("%d", 42);
// a PrintWriter is never closed!

Second, resource leak analysis now leverages knowledge about well-known resource classes that support fluent programming, i.e., instance methods which return this to enable chains of method calls. Where a naive analysis could consider the method result as a new resource coming into scope, special knowledge about these classes informs the analysis that it is one and the same resource. This concerns the following system classes:

from java.io
CharArrayWriter, Console, PrintStream, PrintWriter, StringWriter, Writer
from java.nio.channels
AsynchronousFileChannel, AsynchronousServerSocketChannel, FileChannel, NetworkChannel, SeekableByteChannel, SelectableChannel, Selector, ServerSocketChannel
from java.util
Formatter

The following example is now understood to be safe, because analysis understands that the resource returned by append() is the same as the initial pw:

PrintWriter pw = new PrintWriter("/tmp/log.txt");
pw.printf("%d", 42).append(" is the answer").close();

Generally, resource leak analysis was made more precise regarding several specific situations.

Java Formatter

Java formatter application requires a workspace The Java formatter application will provide a sensible error message if a workspace is required but not provided (-data command line option). This also enables the -help option to be run on the formatter without a workspace specified.

A new bundle services the org.eclipse.jdt.core.JavaCodeFormatter application. This new bundle is part of the JDT feature. Users who are not using the JDT feature to define their set of bundles will need to add org.eclipse.jdt.core.formatterapp to their set of bundles.

Debug

Functional debug expressions Lambda expressions and method references are now supported in debug expressions, such as in the Expressions view and in breakpoint condition expressions.

Debug Expression containing a lambda

Some limitations apply: The feature should be considered a MVP (Minimally Viable Product). It is not yet possible to reference non-public fields and methods of the enclosing class. The evaluation may not work in system classes and some generic contexts.

JDT Developers

New bundle org.eclipse.jdt.core.formatterapp The entry point of the org.eclipse.jdt.core.JavaCodeFormatter application has been moved to a new bundle, org.eclipse.jdt.core.formatterapp.

Previous Up Next

Back to the top