Skip to content
Permalink
Browse files
8273484: Cleanup unnecessary null comparison before instanceof check …
…in java.naming

Reviewed-by: aefimov, dfuchs
  • Loading branch information
turbanoff authored and AlekseiEfimov committed Sep 12, 2021
1 parent f189dff commit 2ee1f96c14b80b63a29445629b1f2e1caf88e075
Showing 13 changed files with 33 additions and 44 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -198,8 +198,8 @@ public void close() throws NamingException {

void setHopCount(int hopCount) {
this.hopCount = hopCount;
if ((refCtx != null) && (refCtx instanceof LdapCtx)) {
((LdapCtx)refCtx).setHopCount(hopCount);
if (refCtx instanceof LdapCtx ldapCtx) {
ldapCtx.setHopCount(hopCount);
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -69,12 +69,10 @@ class SimpleClientId extends ClientId {
}

public boolean equals(Object obj) {
if (obj == null || !(obj instanceof SimpleClientId)) {
if (!(obj instanceof SimpleClientId other)) {
return false;
}

SimpleClientId other = (SimpleClientId)obj;

return super.equals(obj)
&& (username == other.username // null OK
|| (username != null && username.equals(other.username)))
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -65,9 +65,8 @@ final class ConnectionDesc {
* PooledConnection.
*/
public boolean equals(Object obj) {
return obj != null
&& obj instanceof ConnectionDesc
&& ((ConnectionDesc)obj).conn == conn;
return (obj instanceof ConnectionDesc other)
&& other.conn == conn;
}

/**
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -256,7 +256,7 @@ protected Object c_lookup(Name name, Continuation cont)
Object ret = null;
if (resolve_to_penultimate_context(name, cont)) {
ret = a_lookup(name.toString(), cont);
if (ret != null && ret instanceof LinkRef) {
if (ret instanceof LinkRef) {
cont.setContinue(ret, name, this);
ret = null;
}
@@ -348,7 +348,7 @@ protected Object c_resolveIntermediate_nns(Name name, Continuation cont)
Object ret = null;
if (resolve_to_penultimate_context_nns(name, cont)) {
ret = a_resolveIntermediate_nns(name.toString(), cont);
if (ret != null && ret instanceof LinkRef) {
if (ret instanceof LinkRef) {
cont.setContinue(ret, name, this);
ret = null;
}
@@ -368,7 +368,7 @@ protected Object c_lookup_nns(Name name, Continuation cont)
Object ret = null;
if (resolve_to_penultimate_context_nns(name, cont)) {
ret = a_lookup_nns(name.toString(), cont);
if (ret != null && ret instanceof LinkRef) {
if (ret instanceof LinkRef) {
cont.setContinue(ret, name, this);
ret = null;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -121,8 +121,7 @@ public Object getContent() {
* @return true if the object is equal; false otherwise.
*/
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof BinaryRefAddr)) {
BinaryRefAddr target = (BinaryRefAddr)obj;
if (obj instanceof BinaryRefAddr target) {
if (addrType.compareTo(target.addrType) == 0) {
if (buf == null && target.buf == null)
return true;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -278,9 +278,8 @@ public String toString() {
* @see #hashCode
*/
public boolean equals(Object obj) {
return (obj != null &&
obj instanceof CompositeName &&
impl.equals(((CompositeName)obj).impl));
return (obj instanceof CompositeName other) &&
impl.equals(other.impl);
}

/**
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -244,9 +244,8 @@ public String toString() {
*/
public boolean equals(Object obj) {
// %%% check syntax too?
return (obj != null &&
obj instanceof CompoundName &&
impl.equals(((CompoundName)obj).impl));
return (obj instanceof CompoundName other) &&
impl.equals(other.impl);
}

/**
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -103,8 +103,8 @@ public LinkRef(String linkName) {
public String getLinkName() throws NamingException {
if (className != null && className.equals(linkClassName)) {
RefAddr addr = get(linkAddrType);
if (addr != null && addr instanceof StringRefAddr) {
return (String)((StringRefAddr)addr).getContent();
if (addr instanceof StringRefAddr stringRefAddr) {
return (String) stringRefAddr.getContent();
}
}
throw new MalformedLinkException();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -473,8 +473,7 @@ public String toString() {
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof NameImpl)) {
NameImpl target = (NameImpl)obj;
if (obj instanceof NameImpl target) {
if (target.size() == this.size()) {
Enumeration<String> mycomps = getAll();
Enumeration<String> comps = target.getAll();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -104,8 +104,7 @@ public String getType() {
* @see #getType
*/
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof RefAddr)) {
RefAddr target = (RefAddr)obj;
if (obj instanceof RefAddr target) {
if (addrType.compareTo(target.addrType) == 0) {
Object thisobj = this.getContent();
Object thatobj = target.getContent();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -326,8 +326,7 @@ public void clear() {
* @return true if obj is equal to this reference; false otherwise.
*/
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Reference)) {
Reference target = (Reference)obj;
if (obj instanceof Reference target) {
// ignore factory information
if (target.className.equals(this.className) &&
target.size() == this.size()) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -130,8 +130,7 @@ public Object clone() {
* @see #contains
*/
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Attribute)) {
Attribute target = (Attribute)obj;
if (obj instanceof Attribute target) {

// Check order first
if (isOrdered() != target.isOrdered()) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -225,8 +225,7 @@ public String toString() {
* @see #hashCode
*/
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Attributes)) {
Attributes target = (Attributes)obj;
if (obj instanceof Attributes target) {

// Check case first
if (ignoreCase != target.isCaseIgnored()) {

1 comment on commit 2ee1f96

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 2ee1f96 Sep 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.