RFR: 8258422: Cleanup unnecessary null comparison before instanceof check in java.base [v3]
    Andrey Turbanov 
    github.com+741251+turbanoff at openjdk.java.net
       
    Wed Dec 16 19:22:01 UTC 2020
    
    
  
On Wed, 16 Dec 2020 18:27:35 GMT, Aleksei Efimov <aefimov at openjdk.org> wrote:
>> Let's take advantage of "flow scoping" to eliminate some of these casts. A few examples follow.
>
> Hi Andrey,
> 
> Could you, please, also take a look at `java.net.Socket`:
> java/net/Socket.java:        if (bindpoint != null && (!(bindpoint instanceof InetSocketAddress)))
> java/net/Socket.java-            throw new IllegalArgumentException("Unsupported address type");
> And `HttpURLConnection`:
>     sun/net/www/protocol/http/HttpURLConnection.java:                    if (a != null && c instanceof HttpURLConnection) {
>     sun/net/www/protocol/http/HttpURLConnection.java-                        ((HttpURLConnection)c).setAuthenticator(a);
> The following cmd was used to find them: `rgrep -A 1 "= null .* instanceof "`
@AlekseiEfimov in both cases removing `null` check will change semantic of the code. Comparison is not redundant.
-------------
PR: https://git.openjdk.java.net/jdk/pull/20
    
    
More information about the net-dev
mailing list