diff --git a/4.26/images/extract-local-var-after.png b/4.26/images/extract-local-var-after.png new file mode 100644 index 0000000000..41be50bad0 Binary files /dev/null and b/4.26/images/extract-local-var-after.png differ diff --git a/4.26/images/extract-local-var-before.png b/4.26/images/extract-local-var-before.png new file mode 100644 index 0000000000..17cf614057 Binary files /dev/null and b/4.26/images/extract-local-var-before.png differ diff --git a/4.26/jdt.html b/4.26/jdt.html index 557544d718..56298d1534 100644 --- a/4.26/jdt.html +++ b/4.26/jdt.html @@ -105,6 +105,19 @@

Java Editor

+ + Extract local variable improved + + The extract local variable refactoring available from Refactor -> Extract Local Variable has been improved to recognize + situations where adding the local variable may cause a NullPointerException as it precedes code used to check for null. In these cases, + the positioning of the local variable is altered so the null check occurs before the variable declaration. +

For example, in the following class, a call to the String length() method is made after verifying the String variable is not null.

+

Before

+

If we select the s.length() call and choose to extract this to a local variable to replace all occurrences, the result is:

+

Before

+

Note how the declaration is after the if statement to ensure that the check for null occurs first

+ +