RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base

2020-12-15 Thread Andrey Turbanov
8258422: Cleanup unnecessary null comparison before instanceof check in 
java.base

-

Commit messages:
 - [PATCH] Cleanup unnecessary null comparison before instanceof check in 
java.base

Changes: https://git.openjdk.java.net/jdk/pull/20/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=20&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8258422
  Stats: 42 lines in 21 files changed: 0 ins; 0 del; 42 mod
  Patch: https://git.openjdk.java.net/jdk/pull/20.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/20/head:pull/20

PR: https://git.openjdk.java.net/jdk/pull/20


Re: RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base

2020-12-15 Thread Andrey Turbanov
On Sat, 5 Sep 2020 18:55:53 GMT, Andrey Turbanov 
 wrote:

> 8258422: Cleanup unnecessary null comparison before instanceof check in 
> java.base

I believe this changes is useful and still actual:
1. improve code to make it easier to read.
2. performance should be improved a bit too

-

PR: https://git.openjdk.java.net/jdk/pull/20


Re: RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base

2020-12-15 Thread Stuart Marks
On Sun, 4 Oct 2020 11:55:50 GMT, Andrey Turbanov 
 wrote:

>> 8258422: Cleanup unnecessary null comparison before instanceof check in 
>> java.base
>
> I believe this changes is useful and still actual:
> 1. improve code to make it easier to read.
> 2. performance should be improved a bit too

I’ll see if I can get somebody to take a look at this.

-

PR: https://git.openjdk.java.net/jdk/pull/20


Re: RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base

2020-12-15 Thread Aleksei Efimov
On Wed, 2 Dec 2020 20:15:02 GMT, Andrey Turbanov 
 wrote:

>> This seems like a reasonable change, which improves readability.
>> 
>> My preference is to wait a little longer (hopefully no more than a couple of 
>> weeks), until [JEP 394](https://openjdk.java.net/jeps/394) - "Pattern 
>> Matching for instanceof" is finalised, then we can remove the explicit casts 
>> in many of these cases. For example:
>> 
>> --- a/src/java.base/share/classes/java/io/File.java
>> +++ b/src/java.base/share/classes/java/io/File.java
>> @@ -2191,8 +2191,8 @@ public class File
>>   *  {@code false} otherwise
>>   */
>>  public boolean equals(Object obj) {
>> -if ((obj != null) && (obj instanceof File)) {
>> -return compareTo((File)obj) == 0;
>> +if (obj instanceof File file) {
>> +return compareTo(file) == 0;
>>  }
>>  return false;
>>  }
>
> Related issue - https://bugs.openjdk.java.net/browse/JDK-8257448

Hi @turbanoff,

I've logged a JBS issue for tracking this change:
https://bugs.openjdk.java.net/browse/JDK-8258422

JEP 394 is finalized now, so I guess you could follow-up Chris suggestion to 
remove the explicit casts.

After the fix is properly reviewed and marked as ready for the integration 
(you'll need to issue `/integrate` command), once it is done I would happily 
`/sponsor` the change.

With Best Regards,
Aleksei

-

PR: https://git.openjdk.java.net/jdk/pull/20


Re: RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base

2020-12-15 Thread Andrey Turbanov
On Mon, 2 Nov 2020 09:15:31 GMT, Chris Hegarty  wrote:

>> I’ll see if I can get somebody to take a look at this.
>
> This seems like a reasonable change, which improves readability.
> 
> My preference is to wait a little longer (hopefully no more than a couple of 
> weeks), until [JEP 394](https://openjdk.java.net/jeps/394) - "Pattern 
> Matching for instanceof" is finalised, then we can remove the explicit casts 
> in many of these cases. For example:
> 
> --- a/src/java.base/share/classes/java/io/File.java
> +++ b/src/java.base/share/classes/java/io/File.java
> @@ -2191,8 +2191,8 @@ public class File
>   *  {@code false} otherwise
>   */
>  public boolean equals(Object obj) {
> -if ((obj != null) && (obj instanceof File)) {
> -return compareTo((File)obj) == 0;
> +if (obj instanceof File file) {
> +return compareTo(file) == 0;
>  }
>  return false;
>  }

Related issue - https://bugs.openjdk.java.net/browse/JDK-8257448

-

PR: https://git.openjdk.java.net/jdk/pull/20


Re: RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base

2020-12-15 Thread Chris Hegarty
On Sat, 31 Oct 2020 19:37:10 GMT, Stuart Marks  wrote:

>> I believe this changes is useful and still actual:
>> 1. improve code to make it easier to read.
>> 2. performance should be improved a bit too
>
> I’ll see if I can get somebody to take a look at this.

This seems like a reasonable change, which improves readability.

My preference is to wait a little longer (hopefully no more than a couple of 
weeks), until [JEP 394](https://openjdk.java.net/jeps/394) - "Pattern Matching 
for instanceof" is finalised, then we can remove the explicit casts in many of 
these cases. For example:

--- a/src/java.base/share/classes/java/io/File.java
+++ b/src/java.base/share/classes/java/io/File.java
@@ -2191,8 +2191,8 @@ public class File
  *  {@code false} otherwise
  */
 public boolean equals(Object obj) {
-if ((obj != null) && (obj instanceof File)) {
-return compareTo((File)obj) == 0;
+if (obj instanceof File file) {
+return compareTo(file) == 0;
 }
 return false;
 }

-

PR: https://git.openjdk.java.net/jdk/pull/20


Re: RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base [v2]

2020-12-15 Thread Andrey Turbanov
> 8258422: Cleanup unnecessary null comparison before instanceof check in 
> java.base

Andrey Turbanov has updated the pull request with a new target base due to a 
merge or a rebase. The incremental webrev excludes the unrelated changes 
brought in by the merge/rebase. The pull request contains two additional 
commits since the last revision:

 - 8258422: Cleanup unnecessary null comparison before instanceof check in 
java.base
   use instanceof pattern matching
 - 8258422: Cleanup unnecessary null comparison before instanceof check in 
java.base

-

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/20/files
  - new: https://git.openjdk.java.net/jdk/pull/20/files/f09bbd24..603cd364

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=20&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=20&range=00-01

  Stats: 784681 lines in 7664 files changed: 596718 ins; 128884 del; 59079 mod
  Patch: https://git.openjdk.java.net/jdk/pull/20.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/20/head:pull/20

PR: https://git.openjdk.java.net/jdk/pull/20


Re: RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base [v2]

2020-12-15 Thread Alan Bateman
On Tue, 15 Dec 2020 19:52:31 GMT, Andrey Turbanov 
 wrote:

>> 8258422: Cleanup unnecessary null comparison before instanceof check in 
>> java.base
>
> Andrey Turbanov has updated the pull request with a new target base due to a 
> merge or a rebase. The pull request now contains two commits:
> 
>  - 8258422: Cleanup unnecessary null comparison before instanceof check in 
> java.base
>use instanceof pattern matching
>  - 8258422: Cleanup unnecessary null comparison before instanceof check in 
> java.base

src/java.base/windows/classes/sun/nio/fs/WindowsPath.java line 803:

> 801: if (obj instanceof WindowsPath path) {
> 802: return compareTo(path) == 0;
> 803: }

Can you do the same in UnixPath?

-

PR: https://git.openjdk.java.net/jdk/pull/20