A JBoss Project
Red Hat

JBoss Tools and Red Hat CodeReady Studio for Eclipse 2021-03

posted by Jeff Maury on Apr 20, 2021.

release jbosstools devstudio jbosscentral codereadystudio

Comments

JBoss Tools 4.19.0 and Red Hat CodeReady Studio 12.19 for Eclipse 2021-03 are here waiting for you. Check it out!

crstudio12

Installation

Red Hat CodeReady Studio comes with everything pre-bundled in its installer. Simply download it from our Red Hat CodeReady product page and run it like this:

java -jar codereadystudio-<installername>.jar

JBoss Tools or Bring-Your-Own-Eclipse (BYOE) CodeReady Studio require a bit more:

This release requires at least Eclipse 4.19 (2021-03) but we recommend using the latest Eclipse 4.19 2021-03 JEE Bundle since then you get most of the dependencies preinstalled.

Java11 is now required to run Red Hat Developer Studio or JBoss Tools (this is a requirement from Eclipse 4.17). So make sure to select a Java11 JDK in the installer. You can still work with pre-Java11 JDK/JRE and projects in the tool.

Once you have installed Eclipse, you can either find us on the Eclipse Marketplace under "JBoss Tools" or "Red Hat CodeReady Studio".

For JBoss Tools, you can also use our update site directly.

http://download.jboss.org/jbosstools/photon/stable/updates/

What is new?

Our main focus for this release was an improved tooling for the Quarkus framework, improvements for container based development and bug fixing.

OpenShift

Login to Developer Sandbox from the tooling

Red Hat provides an online OpenShift environment called Developer Sandbox that makes it easy for developers to build, test and deploy cloud native applications and microservices.

In order to use Developer Sandbox, you must own a Red Hat SSO account (which can be linked to social accounts like GitHub,…​). Once logged in into Red Hat SSO, you will get an environment provisioned in Developer Sandbox but the first time you will try to login in to Developer Sandbox, your account needs to be verified (in order to prevent crypto miners and robots) thus you need to go through a verification phase where you will be asked to provide:

  • first your phone number and country code

  • then a verification code that you will receive on your smartphone.

So it is now possible to provision and log in to Developer Sandbox from the OpenShift tooling and connect it to the Developer Sandbox environment.

Open the OpenShift Application Explorer view (Window → Show View → Other…​, enter open and double click on OpenShift Application Explorer):

devsandbox1

Right click on the first node and select the Login context menu:

devsandbox2

In order to provision the Developer Sandbox environment, click on the Red Hat Developer Sandbox link: a browser window will open and you will be required to login to your Red Hat SSO account:

devsandbox3

Login to your account (please note that if you don’t have a Red Hat account, you can create a new one). Once you’re logged in, you should see the following window:

devsandbox4

Enter your contry code (+XX) and phone number and click the Verify button:

You will be required to provide the verification code that you should have received on your phone:

devsandbox5

Once your Developer Sandbox environment is provisioned; you will see the following window:

devsandbox6

Click on the Ǹext button to log in to your Developer Sandbox environment:

devsandbox7

Click on the DevSandbox link and log in with the same credentials: you will see the following window:

devsandbox8

Click on the Display Token link and the click on the Finish button, you should be back to the Login wizard:

devsandbox9

Please note that the URL and Token fields have been updated. Click the Finish button, the OpenShift Application Explorer will be updated with the Developer Sandbox URL and if you expand it, you will see 3 namespaces/projects available for you to start playing with:

devsandbox10

You’re now ready to work against this environment for free !!!.

Browser based login to an OpenShift cluster

When it comes to login to a cluster, OpenShift Tools supported two different authentication mechanisms:

  • user/password

  • token

The drawback is that it does not cover clusters where a more enhanced and modern authentication infrastructure is in place. So it is now possible to login to the cluster through an embedded web browser.

In order to use it, go to the Login context menu from the Application Explorer view:

weblogin1

Click on the Retrieve token button and an embedded web browser will be displayed:

weblogin2

Complete the workflow until you see a page that contains Display Token:

weblogin3

Click on Display Token:

The web browser is automatically closed and you’ll notice that the retrieved token has been set in the original dialog:

weblogin4

Devfile registries management

Since JBoss Tools 4.18.0.Final, the preferred way of developing components is now based on devfile, which is a YAML file that describe how to build the component and if required, launch other containers with other containers. When you create a component, you need to specify a devfile that describe your component. So either you component source contains its own devfile or you need to pick a devfile that is related to your component. In the second case, OpenShift Tools supports devfile registries that contains a set of different devfiles. There is a default registry (https://github.com/odo-devfiles/registry) but you may want to have your own registries. It is now possible to add and remove registries as you want.

The registries are displayed in the OpenShift Application Explorer under the Devfile registries node:

registries1

Please note that expanding the registry node will list all devfiles from that registry with a description:

registries2

A context menu on the Devfile registries node allows you to add new registries, and on the registry node to delete it.

Devfile enhanced editing experience

Although devfile registries can provide ready-to-use devfiles, there may be some advanced cases where users need to write their own devfile. As the syntax is quite complex, the YAML editor has been completed so that to provide:

  • syntax validation

  • content assist

Support for Python based components

Python-based components were supported but debugging was not possible. This release brings integration between the Eclipse debugger and the Python runtime.

Quarkus

Support for environment variables in Run/debug Quarkus configurations

Environment variables is one way to override properties values in the Quarkus properties file. It is now possible to specify environment variables in a Run/debug Quarkus configuration.

Server Tools

Wildfly 23 Server Adapter

A server adapter has been added to work with Wildfly 23.

EAP 7.4 Beta Server Adapter

The server adapter has been adapted to work with EAP 7.4 Beta.

Hibernate Tools

Hibernate Runtime Provider Updates

A number of additions and updates have been performed on the available Hibernate runtime providers.

Runtime Provider Updates

The Hibernate 5.4 runtime provider now incorporates Hibernate Core version 5.4.30.Final and Hibernate Tools version 5.4.30.Final.

Platform

Views, Dialogs and Toolbar

Filter field for configuration details

A filter field has been added to the Installation Details > Configuration tab. This allows much faster lookup of specific information from the system details by showing only lines containing the filter criteria.

configuration filter
Preference to remember the last used page in search dialog

The Remember last used page check box was previously available from the Search dialog > Customize…​ > Search Page Selection dialog, which was not intuitive and hard to find. Now, the check box is moved to the Search preference page.

A new preference Remember last used page in the Search dialog has been added to Preferences > General > Search page. This new preference is enabled by default. image::https://www.eclipse.org/eclipse/news/4.18/images/remember-last-used.png[]

Text Editors

Horizontal Scrolling in Text Editor

You can now scroll horizontally in the Text Editor using Shift+Mouse Wheel and touchpad gestures on Windows. Horizontal scrolling with touchpad already works on Linux and macOS.

Open-with does not store the editor relationship anymore

The menu entry Open With  …​ does not store the selected editor as default editor for the selected file as this was undesired in most cases and lead to confusion. Also, removing this association was not easy for the end user. The user can still assign a editor to a certain file type via the Open With  Other…​ dialog.

Debug

Find Next/Previous in Console View

In the Console view, you can repeat your last search in the forward or backward direction in the following ways:

  • Right-click in the Console view, then select Find Next or Find Previous.

  • Use the keyboard shortcuts Ctrl+K or Ctrl+Shift+K.

console find next find previous 45017
Disable All in Breakpoints view

In the Breakpoints view, you can disable all the breakpoints using the new Disable All context-menu option available on right-click.

disable allbreakpoints
Terminate descendants of operating-system processes launched by Eclipse

Some types of launch-configurations start operating-system processes when launched from Eclipse. When you terminate the corresponding process before it completes (for example by clicking the terminate button, the red square) that operating-system process is destroyed. Now the descendants of that process, its child-processes created by the main-process and their children recursively, are destroyed too.

Termination of child processes of launched OS processes can be configured

Since Eclipse 4.18 child processes (descendants) of an operating system process launched from Eclipse are terminated too, when the launched process is terminated (for example by clicking the terminate button).

It is now possible to configure in the Launch Configuration whether the child processes of a launched process should be terminated too or if they should stay alive, in case the launched processes is terminated. You can control this with the checkbox Terminate child processes if terminating the launched process in the Common tab of the Run/Debug Configurations dialog. By default this checkbox is selected and child processes are terminated too.

configure child process termination

Preferences

External browsers on Windows

On Windows, the list of recognized External web browsers has been updated to include:

  • Microsoft Edge (%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe)

browsers windows update

Enable word wrap on console output

A new preference Enable word wrap is available in the Console preference page. This setting persists the current state of the "Word wrap" toggle on the console view between user sessions. By default, word wrapping is disabled on console output.

console preferences word wrap

Themes and Styling

New "System" theme

A new "System" theme is available in the Appearance preference page. This theme is built using system colors, and as a consequence integrates well in any OS and OS theme.

This screenshot shows the System theme in action under several GTK themes:

GTK Adwaita:

systemTheme gtkAdawaita

GTK Adwaita Dark:

systemTheme gtkAdawaitaDark

GTK Kripton:

systemTheme gtkKripton

GTK Dark Mint:

systemTheme gtkDarkMint
Windows dark theme styles progress bars

The progress bar in the dark theme on Windows OS is now styled:

progressbar dark win32
Light theme on macOS

The Light theme for macOS has been updated to fit the latest macOS design.

Old:

macTheme light old

New:

macTheme light new

General Updates

Equinox Linux Security JNA Fragment

A new fragment has been added for Linux password security using JNA. This new fragment replaces the old JNI x86_64-specific fragment and supports all Linux architectures.

Ant 1.10.9

Eclipse has adopted Ant version 1.10.9.

Java Developement Tools (JDT)

JUnit

JUnit 5.7.1

JUnit 5.7.1 is here and Eclipse JDT has been updated to use this version.

Java Editor

Quick assist to create try-with-resources

For expressions returning a type that is AutoCloseable there’s a new quick assist (Ctrl+1) available: Assign to new local variable in try-with-resources.

try with resources before

It creates a new try-with-resources block with the expression assigned to a resource variable. The variable type and name can be selected from a few suggestions:

try with resources after

The default hotkey sequence for this quick assist is Ctrl+2 followed by T.

Add catch clause to try-with-resources assists

There are multiple assists to surround auto-closeable statements in a try-with-resources statement including Surround with > Try-with-resources Block. Now, all forms will add a catch clause for any exceptions (such as IOException) thrown by the auto-close if not already handled via an existing catch clause or throws directive. In the case where the existing code catches or throws an exception that sub-classes the exceptions of the new catch clause, an additional catch clause will be added to rethrow the exception to ensure code logic remains consistent.

add catch clause to try with resources before
add catch clause to try with resources after
Quick fix to create permitted type declaration

You can use the following quick fixes (Ctrl+1) to create a new permitted class or interface declaration:

create permitted type declaration

The created type will declare the sealed type as its super type and it can be declared as final, non-sealed, or sealed with the available quick fixes for further inheritance control.

Java Feature clean ups

A new tab named Java Feature has been added to the Clean Up preferences. It lists the clean up options that introduce the use of language features from different Java versions. Relevant clean up options from other tabs have also been moved to this new tab.

You can use these clean ups while upgrading the Java version in your code.

java feature preferences
Pattern matching for instanceof clean up

A new clean up has been added that uses pattern matching for the instanceof operator when possible.

It is only applicable for Java 15 or higher when preview features are enabled.

To apply the clean up, select Pattern matching for instanceof check box on the Java Feature tab in your clean up profile.

pattern matching preferences

For the given code:

pattern matching before

One gets:

pattern matching after
Reduce indentation clean up

A new clean up has been added that removes useless indentation when the opposite workflow falls through.

When several blocks fall through, it reduces the block with the greatest indentation. It can negate an if condition if the else statements fall through.

To apply the clean up, select Reduce indentation when possible check box on the Code Style tab in your clean up profile.

reduce indentation preferences

For the given code:

reduce indentation before

One gets:

reduce indentation after
Extract increment clean up

A new clean up has been added that moves increment or decrement outside an expression.

A prefix increment/decrement (i`) first changes the value of the variable and then returns the updated value. A postfix increment/decrement (`i) first returns the original value and then changes the value of the variable.

But let’s look at this code:

int i = j++;

Most of the developers hardly remember which from the increment or the assignment comes first. One way to make the code obvious is to write the increment/decrement in a dedicated statement:

int i = j;
j++;

And so for the prefix expressions:

int i = ++j;

…​it goes like this:

j++;
int i = j;

The cleanup moves a prefix expression above the statement and a postfix expression below. It does not move increments from loop condition and it does not cleanup several increments in the same statement. The increment/decrement is always rewritten as a postfix expression for standardization.

To apply the clean up, select Extract increment/decrement from statement check box on the Code Style tab in your clean up profile.

extract increment preferences

For the given code:

extract increment before

One gets:

extract increment after
Use Comparator.comparing() clean up

A new clean up has been added that replaces a plain comparator instance by a lambda expression passed to a Comparator.comparing() method.

The feature is enabled only with Java 8 or higher.

The Comparator type must be inferred by the destination of the comparator. The algorithm of the comparator must be standard and based on one field or method. The cleanup can handle the null values and reversed orders.

To apply the clean up, select Use Comparator.comparing() check box on the Java Feature tab in your clean up profile.

comparator comparing preferences

For the given code:

comparator comparing before

One gets:

comparator comparing after
Multi-catch clean up

A new clean up has been added that converts catch clauses with same body to Java 7’s multi-catch.

The feature is enabled only with Java 7 or higher.

To apply the clean up, select Use Multi-catch check box on the Java Feature tab in your clean up profile.

multi catch preferences

For the given code:

multi catch before

One gets:

multi catch after
Convert fields into local variables

A new clean up has been added that refactors a field into a local variable if its use is only local.

The previous value should not be read. The field should be private. The field should not be final. The field should be primitive. The field should not have annotations.

To apply the clean up, select Convert fields into local variables if the use is only local check box on the Optimization tab in your clean up profile.

convert fields preferences

For the given code:

convert fields before

One gets:

convert fields after
Static inner class clean up

A new clean up has been added that makes inner class static if it doesn’t use top level class members.

To apply the clean up, select Make inner classes static where possible check box on the Optimization tab in your clean up profile.

static inner class preferences

For the given code:

static inner class before

One gets:

static inner class after
Use String.replace() clean up

A new clean up has been added that replaces String.replaceAll() by String.replace() when the pattern is a plain text.

The pattern must be constant.

To apply the clean up, select Use String.replace() instead of String.replaceAll() when no regex used check box on the Optimization tab in your clean up profile.

string replace preferences

For the given code:

string replace before

One gets:

string replace after
Primitive comparison clean up

A new clean up has been added that replaces the compareTo() method by a comparison on primitive.

It improves the space and time performance. The compared value must be a primitive.

To apply the clean up, select Primitive comparison check box on the Optimization tab in your clean up profile.

primitive comparison preferences

For the given code:

primitive comparison before

One gets:

primitive comparison after
Primitive parsing clean up

A new clean up has been added that avoids to create primitive wrapper when parsing a string.

The object should be used as a primitive and not as a wrapper.

To apply the clean up, select Primitive parsing check box on the Optimization tab in your clean up profile.

primitive parsing preferences

For the given code:

primitive parsing before

One gets:

primitive parsing after
Pull down common code from if/else statement clean up

A new clean up has been added that extracts common code from the end of an if / else if / else control flow.

Ultimately it removes the empty and passive if conditions.

The control flow should have an else clause and the duplicate code should not rely on variables declared in the block.

The statement matching performs a deep analysis. All the blocks should end with the same set of statements, or the blocks with different code should fall through with a jump statement (return, throw, continue or break).

To apply the clean up, select Pull down common code from if/else statement check box on the Duplicate code tab in your clean up profile.

control flow merge preferences

For the given code:

control flow merge before

One gets:

control flow merge after

And for the given code where all tails of blocks are identical except one block which falls through:

control flow merge jump statement before

The identical tails of blocks have been pulled down from the control flow and the falling through block has been left as it is:

control flow merge jump statement after
String.substring() clean up

A new clean up has been added that removes the second substring() parameter if this parameter is the length of the string. It’s the default value.

It must reference the same expression.

The expression must be passive.

To apply the clean up, select Redundant String.substring() parameter check box on the Unnecessary code tab in your clean up profile.

substring preferences

For the given code:

substring before

One gets:

substring after
Unreachable block clean up

A new clean up has been added that detects two if conditions that are identical and removes the second one.

The conditions should be passive.

No exceptions should be awaited.

It doesn’t create unreachable code below the if statement which would create a compile error. That is to say it avoids the case where only the removed block doesn’t fall through, all the other cases fall through, there are an else clause (not only if/else clauses) and a statement after the control workflow.

To apply the clean up, select Unreachable block check box on the Unnecessary code tab in your clean up profile.

unreachable block preferences

For the given code:

unreachable block before

One gets:

unreachable block after
Unlooped while clean up

A new clean up has been added that replaces a while loop that always terminates during the first iteration by an if.

The loop should not contain any continue statement.

The loop should only contain break statements without statements after.

To apply the clean up, select Convert loop into if when possible check box on the Unnecessary code tab in your clean up profile.

unlooped while preferences

For the given code:

unlooped while before

One gets:

unlooped while after
Source Fixing clean ups

A new tab named Source Fixing has been added to the Clean Up preferences. It lists the clean up options that fixes the behavior of the code. The Compare with != 0 for bitwise expression clean up option from Code style tab have also been moved to this new tab.

Use it carefully. You may get an unexpected behavior. It may trigger zombie code. A zombie code is a dead code that is dead because an error occurs before. The day someone fixes the error, the zombie code comes back to life and alters the behavior. Although most of the cleanups need review, those ones need testing.

source fixing preferences
Object.equals() on non null clean up

A new clean up has been added that inverts calls to Object.equals(Object) and String.equalsIgnoreCase(String) to avoid useless null pointer exception.

The caller must be nullable.

The parameter must not be nullable.

Beware! By avoiding null pointer exceptions, the behavior may change!

To apply the clean up, select Avoid Object.equals() or String.equalsIgnoreCase() on null objects check box on the Source Fixing tab in your clean up profile.

invert equals preferences

For the given code:

invert equals before

One gets:

invert equals after
Comparison to zero clean up

A new clean up has been added that fixes Comparable.compareTo() usage.

The code is not supposed to predict the 1 and -1 values; it is supposed to get zero or a value lesser or greater than zero.

Beware! The behavior may change if you implement a custom comparator!

To apply the clean up, select Compare to zero check box on the Source Fixing tab in your clean up profile.

comparison zero preferences

For the given code:

comparison zero before

One gets:

comparison zero after
Completion overwrites in Java editor

The Java Editor now uses Completion overwrites as the default. If Completion overwrites is on, the completion text replaces the characters following the caret position until the end of the word. If Completion inserts is on, the completion text is inserted at the caret position, so it never overwrites any existing text. Note that pressing Ctrl when applying a completion proposal toggles between the two insertion modes.

You can change the default in the Java > Editor > Content Assist preference page.

Insert best guessed parameters in Java editor

Instead of simply inserting the method parameter names as placeholders, when a method is completed, the Java Editor now inserts the best guessed parameters by default.

You can change the default in the Java > Editor > Content Assist preference page.

Quick assist to create new implementation

Invoking the Quick Assist (Ctrl+1) to create new implementation on an interface or abstract class declaration launches the New Java Class wizard:

quick assist interface
Quick fixes on permitted types

You can add sealed, non-sealed, or final modifiers on permitted type declarations, as applicable, using the new Quick Fixes (Ctrl+1).

On a permitted class declaration:

permitted class

On a permitted interface declaration:

permitted interface
Convert to switch expression

A new quick assist and clean up has been added that converts switch statements to switch expressions (Java 14 or higher) where possible.

Switch statements that use control statements such as nested switch statements, if/else blocks, for/while loops are not considered as is the case for return/continue statements. All cases of the switch statement must either have a last assignment statement that sets the same variable/field as other cases, or else has a throw statement. Fall-through is allowed between cases but only if there are no other statements in between. The switch statement must have a default case unless the switch expression is an enum type and all possible enum values are represented in the cases.

To apply the quick assist, press Ctrl+1 on the target switch statement and select Convert to switch expression, if offered.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Convert to switch expression check box on the Code Style tab (or the Java Feature tab starting from Eclipse 2021-03).

switch expressions preferences

For the given code:

switch expressions before

One gets:

switch expressions after
Uses the else-if pseudo keyword

A new clean up has been added that combines nested if statement in else block to else if.

Beware for any comments after the else keyword. It will be lost.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Combine nested 'if' statement in 'else' block to 'else if' check box on the Code Style tab.

For the given code:

else if before

One gets:

else if after
Bitwise expressions in comparisons

A new clean up has been added that replaces the > operator with != when the comparison expression has a bitwise expression operand and a 0 operand.

This resolves an anti-pattern for such kind of comparisons, which can also be a bug when the bitwise expression is involving a negative constant value. This code smell is further described by the FindBugs project as bug description "BIT: Check for sign of bitwise operation".

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog select Compare with != 0 for bitwise expression on the Code Style tab (or the Source fixing tab starting from Eclipse 2021-03).

bitwise expressions preferences

For the given code:

bitwise expressions before

You get this after the clean up:

bitwise expressions after
Pull up assignment

A new clean up has been added that moves assignments inside an if condition above the if node.

It improves the readability of the code.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Pull up assignment check box on the Code Style tab.

For the given code:

pull up assignment before

One gets:

pull up assignment after
Use switch

A new clean up has been added that replaces if/else if/else blocks to use switch when possible.

It converts to switch when there are more than two cases.

It does not convert if the discriminant can be null, that is to say only primitive.

It does a variable conflict analyze.

The case value can be literals or constants.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Convert if/else if/else chain to switch check box on the Code Style tab.

For the given code:

use switch before

One gets:

use switch after
Add elements in collections without loop

A new clean up has been added that uses Collection.addAll() or Collections.addAll() instead of a for loop.

It refactors for loops with index, for loops with iterator and foreach loops.

If the source is an array, the list is raw, and the Java version is 1.5 or higher, we use Arrays.asList() to handle the erasure type. It doesn’t decrease the performance.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Add elements in collections without loop check box on the Code Style tab.

add remove preferences

For the given code:

add remove before

One gets:

add remove after
Use ternary operator

A new clean up has been added that replaces (X && Y) || (!X && Z) by X ? Y : Z.

The operands must be passive and boolean.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Replace (X && Y) || (!X && Z) by X ? Y : Z check box on the Duplicate Code tab.

ternary operator preferences

For the given code:

ternary operator before

One gets:

ternary operator after
Use '==' or '^' on booleans

A new clean up has been added that replaces (X && !Y) || (!X && Y) by X ^ Y and replaces (X && Y) || (!X && !Y) by X == Y.

It only works on boolean.

It works with lazy or eager operators.

The operands must be passive.

It does not matter an operand is on the left or right.

It does a deep negation expression analyze.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Use '==' or '^' on booleans check box on the Duplicate Code tab.

For the given code:

xor before

One gets:

xor after
Redundant falling through blocks

A new clean up has been added that detects a list of statements that ends with a jump statement (return, break, continue or throw), and has the same list of statements below that.

It detects similar statements. It also checks that the declarations of the variables in the statements are the same. It looks for redundant statements in if, else, catch and finally but not in loops.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Remove redundant end of block with jump statement check box on the Duplicate Code tab.

For the given code:

redundant falling blocks before

One gets:

redundant falling blocks after
Redundant if condition

A new clean up has been added that removes a condition on an else that is negative to the condition of the previous if.

The condition must be passive. The removed code should not throw an expected exception. The cleanup uses a deep condition comparison algorithm.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Redundant if condition check box on the Duplicate Code tab.

For the given code:

if condition before

One gets:

if condition after
Use Objects.hash()

A new clean up has been added that rewrites Eclipse-autogenerated hashCode() method by Eclipse-autogenerated hashCode() method for Java 7 using Objects.hash().

Let’s remind that you can autogenerate your hashCode() and equals() methods by right-clicking on your class, selecting Source and clicking on Generate hashCode() and equals() methods…​. Since Eclipse 2018-09, a checkbox allows you to generate your methods using Java 7 API. This cleanup rewrites your method as if it has been generated using this option.

This clean up does not generate again your method from scratch, it rewrites it using a more modern syntax. That is to say, if your method is missing or voluntary does not process a field, this field still won’t be processed.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Use Objects.hash() check box on the Unnecessary Code tab (or the Java Feature tab starting from Eclipse 2021-03).

hash preferences

For the given code:

hash before

One gets:

hash after
Use String.join()

A new clean up has been added that uses String.join() when possible.

It detects all types of for loops. The delimiter can be added before or after. The condition can be a boolean or an index comparison.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Use String.join() check box on the Unnecessary Code tab (or the Java Feature tab starting from Eclipse 2021-03).

For the given code:

string join before

One gets:

string join after
Use Arrays.fill()

A new clean up has been added that replaces for loops to use Arrays.fill() where possible.

The value must be hard-coded.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Use Arrays.fill() check box on the Unnecessary Code tab.

For the given code:

arrays fill before

One gets:

arrays fill after
Evaluate without null check

A new clean up has been added that removes redundant null checks.

It removes null check on value before equals() or equalsIgnoreCase() method and before instanceof expression.

It only removes redundant passive expressions.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Evaluate without null check check box on the Unnecessary Code tab.

For the given code:

redundant null check before

One gets:

redundant null check after
Avoid double negation

A new clean up has been added that reduces double negation in boolean expression.

It removes negations on both operands in an equality/difference operation.

It prefers equality/difference operation rather than negated operand.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Double negation check box on the Unnecessary Code tab.

For the given code:

double negation before

One gets:

double negation after
Redundant comparison statement

Removes useless bad value checks before assignments or return statements. Such useless bad value checks are comparing an expression against bad value, then either assigning bad value or the expression depending on the result of the bad value check. It is simpler to directly assign the expression.

The expression should be passive.

The excluded value should be hard coded.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Remove redundant comparison statement check box on the Unnecessary Code tab.

For the given code:

redundant comparison statement before

One gets:

redundant comparison statement after
Unnecessary super() call

A new clean up has been added that removes call to super constructor with empty arguments.

Such a call is redundant. See JLS section 12.5 for more info.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Remove redundant super() call in constructor check box on the Unnecessary Code tab.

For the given code:

redundant super before

One gets:

redundant super after
Initialize collection at creation

A new clean up has been added that replaces the creation of a new Collection, then invoking Collection.addAll() on it, by the creation of the new Collection with the other Collection as parameter.

Only well known collection classes are refactored to avoid behavior changes. The cleanup is enabled only if there is no useful instantiation parameters.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Initialize collection at creation check box on the Unnecessary Code tab.

For the given code:

collection cloning before

One gets:

collection cloning after
Initialize map at creation

A new clean up has been added that replaces creating a new Map, then invoking Map.putAll() on it, by creating the new Map with the other Map as parameter.

Only well known map classes are refactored to avoid behavior changes. The cleanup is enabled only if there is no useful instantiation parameters.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Initialize map at creation check box on the Unnecessary Code tab.

For the given code:

map cloning before

One gets:

map cloning after
Remove overridden assignment

A new clean up has been added that removes passive assignment when the variable is reassigned before being read.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Remove overridden assignment check box on the Unnecessary Code tab.

For the given code:

overridden assignment before

One gets:

overridden assignment after
Raise embedded if into parent if

A new clean up has been added that merges inner if statement into the parent if statement.

The cleanup checks that there is no else statement.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Raise embedded if into parent if check box on the Unnecessary Code tab.

For the given code:

embedded if before

One gets:

embedded if after
Redundant return

A new clean up has been added that removes useless lone return at the end of a method or lambda.

The cleanup checks that there is no value on the return statement.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Remove useless return check box on the Unnecessary Code tab.

For the given code:

redundant return before

One gets:

redundant return after
Redundant continue

A new clean up has been added that removes useless lone continue at the end of a loop.

A continue statement at the end of a loop is removed. A continue statement at the end of a control statement is removed if the control statement is at the end of a loop. A continue statement is kept if it has a label.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Remove useless continue check box on the Unnecessary Code tab.

For the given code:

redundant continue before

One gets:

redundant continue after
Use try-with-resource

A new clean up has been added that changes code to make use of Java 7 try-with-resources feature. In particular, it removes now useless finally clauses.

It may move an inner closeable assignment as a resource. It handles finally with a simple close() invocation, a null-check and remaining statements below.

It is only enabled from Java 7 and it also handles the Java 9 syntax.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Use try-with-resource check box on the Unnecessary Code tab (or the Java Feature tab starting from Eclipse 2021-03).

For the given code:

try with resource before

One gets:

try with resource after
Exit loop earlier

A new clean up has been added that adds a break to avoid passive for loop iterations.

The inner assignments must not do other different assignments after (assign other values or assign into other variables).

There must be no side effects after the first assignments.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Exit loop earlier check box on the Optimization tab.

For the given code:

break loop before

One gets:

break loop after
Use StringBuilder

A new clean up has been added that replaces String concatenation by StringBuilder when possible.

It uses StringBuffer for Java 1.4-.

It only replaces strings on several statements and the concatenation should have more than two pieces.

The variable should be only concatenated and it should retrieve the string once.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Replace String concatenation by StringBuilder check box on the Optimization tab.

For the given code:

stringbuilder before

One gets:

stringbuilder after
Primitive serialization

A new clean up has been added that replaces a primitive boxing to serialize by a call to the static toString() method.

It works for all the primitive types: boolean, char, byte, short, int, long, float and double.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Primitive serialization check box on the Optimization tab.

For the given code:

primitive serialization before

One gets:

primitive serialization after
Prefer boolean literal

A new clean up has been added that replaces Boolean.TRUE/Boolean.FALSE by true/false when used as primitive.

To apply the clean up, invoke Source > Clean Up…​, use a custom profile, and on the Configure…​ dialog, select Prefer boolean literals check box on the Optimization tab.

boolean literal preferences

For the given code:

boolean literal before

One gets:

boolean literal after
Diamond operator <> (Remove redundant type arguments)

The clean up Remove redundant type arguments has been renamed Use diamond operator and is still available in the Unnecessary Code tab in Eclipse 2020-12.

The clean up will be moved to the future Java Feature tab in Eclipse 2021-03.

Java Views and Dialogs

A new preference option has been added and enabled by default: Preferences > Java > Enable parallel index search. Depending on the available hardware, this option should improve performance for all index based Java search operations, but could also lead to possible regressions. To switch back to the old sequential index search, turn this option off:

parallel index search
Coloring restricted identifiers

A new option named Restricted identifiers has been added under Java category in Java > Editor > Syntax Coloring preferences.

Some identifiers (e.g. var, yield, record etc.) are restricted identifiers because they are not allowed in some contexts. Semantic highlighting options for such identifiers can be controlled by the element Restricted identifiers under Java category in Java > Editor > Syntax Coloring preference page.

restricted identifier preference
Externally annotate sources

The concept of external null annotations has been extended to apply to source folders, too.

External annotations were introduced in Eclipse 4.5 in order to overlay not-editable library classes with null annotations to specify the null contract against which library calls should be analysed. You can now apply the same concept for another kind of classes that should not be edited: generated source code.

In the Java Build Path dialog, also source folders now have a node External annotations where a path to Eclipse External Annotation files (.eea) can be configured.

annotate sources config

Given a project that is configured for annotation based null analysis, and given a Java class inside a source folder configured for external annotations, the editor now offers a quick assist (Ctrl+1) for annotating individual type references in the signatures of methods and fields.

annotate sources assist

The selected option will record that the return type should be interpreted as @NonNull List<Attribute> (the popup to the right showing the internal format how this annotation will be stored in an .eea file). With this annotation in place, the annotated signature will be shown in hovers and will be used for null analysis:

annotate sources effect
static import org.mockito.Mockito.* available as favorite

Imports for static org.mockito.Mockito. are added to the Java favorites in the preferences under *Java > Editor > Content Assists > Favorites. This way the organize imports action in the IDE will automatically add static imports to this class when you use the Mockito library in your tests.

Fine-grained search for permitted types

You can perform a fine-grained search for permitted type declarations in the Search dialog (Ctrl+H) > Java Search > Limit To > Match Locations with the new option:

search permitted type
Sort library entries alphabetically in Package Explorer enabled by default

The Preferences > Java > Appearance > [x] Sort library entries alphabetically in Package Explorer is now enabled by default. This makes it easier for you to see if a library is available or not.

If you want to see the order in which the libraries are added to the classpath, e.g. to understand classpath loading issues, you can disable the preference.

Debug

Toggle tracepoints in editor ruler

A new Toggle Tracepoint context-menu entry has been added to the Java Editor line ruler. Both the Toggle Tracepoint options i.e. the new context-menu entry and the existing option under Run menu have a new icon and are now available for Java class files also along with Java source files.

toggle tracepoints
Toggle breakpoint on a list of methods including abstract method

You can now Toggle Method Breakpoint on a list of methods which includes an abstract method.

debug toggle breakpoint
Support for @argfiles when launching

A new check box was added to the Arguments tab for Java based launch configurations (Java Application, JUnit, and others) for writing arguments into an @argfile. This is disabled below Java 9 and can be enabled for Java programs launched with Java 9 and above.

launch with argfile
Stabilized logical structures in Variables view with active GC

The Debug view no longer breaks when logical structures are shown while the application’s garbage collector is active (com.sun.jdi.ObjectCollectedException occurred while retrieving value).

Java Formatter

Annotations wrapping

The formatter now allows more control over how multiple annotations on a single element should be divided into lines. Previously, they could either all be placed in a single line along with the annotated element, or each in a separate line. The settings that controlled this behavior (in the New Lines > After annotations section) now only control a line break between the last annotation and the annotated element. Line breaks between annotations are controlled by a new group of settings in the Line Wrapping > Wrapping Settings > Annotations section.

Just like with standard wrapping settings, they can be set to keep everything in a single line (Do not wrap), each annotation in a separate line (Wrap all elements), or only break lines that exceed the width limit (Wrap where necessary). The last option along with the Never join already wrapped lines setting effectively means manual control over each case. The annotation wrapping settings differ from other wrapping settings in that the indentation control is not available.

The formatter configuration sections can be found in the Profile Editor (Preferences > Java > Code Style > Formatter > Edit…​).

formatter wrap annotations

And more…​

You can find more noteworthy updates in on this page.

What is next?

Having JBoss Tools 4.19.0 and Red Hat CodeReady Studio 12.19 out we are already working on the next release.

Enjoy!

Jeff Maury

Latest posts

JBoss Tools 4.29.1.Final for Eclipse 2023-09

by Stéphane Bouchet on Jun 13, 2024.

JBoss Tools 4.29.0.Final for Eclipse 2023-09

by Stéphane Bouchet on Nov 02, 2023.

JBoss Tools 4.28.0.Final for Eclipse 2023-06

by Stéphane Bouchet on Jul 03, 2023.

JBoss Tools for Eclipse 2023-06M2

by Stéphane Bouchet on Jun 05, 2023.

JBoss Tools 4.27.0.Final for Eclipse 2023-03

by Stéphane Bouchet on Apr 07, 2023.

Looking for older articles ? See the Archived entries.
back to top