Skip to content

Commit db0c8d5

Browse files
turbanoffplummercj
authored andcommitted
8274232: Cleanup unnecessary null comparison before instanceof check in jdk.jdi
Reviewed-by: cjplummer, sspitsyn
1 parent 1830b8d commit db0c8d5

20 files changed

+46
-59
lines changed

src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/Commands.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -708,9 +708,9 @@ void doKill(ThreadReference thread, StringTokenizer t) {
708708
}
709709
String expr = t.nextToken("");
710710
Value val = evaluate(expr);
711-
if ((val != null) && (val instanceof ObjectReference)) {
711+
if (val instanceof ObjectReference object) {
712712
try {
713-
thread.stop((ObjectReference)val);
713+
thread.stop(object);
714714
MessageOutput.println("killed", thread.toString());
715715
} catch (InvalidTypeException e) {
716716
MessageOutput.println("Invalid exception object");
@@ -1804,8 +1804,7 @@ void doLock(StringTokenizer t) {
18041804
Value val = evaluate(expr);
18051805

18061806
try {
1807-
if ((val != null) && (val instanceof ObjectReference)) {
1808-
ObjectReference object = (ObjectReference)val;
1807+
if (val instanceof ObjectReference object) {
18091808
String strVal = getStringValue();
18101809
if (strVal != null) {
18111810
MessageOutput.println("Monitor information for expr",
@@ -1900,8 +1899,7 @@ void doDisableGC(StringTokenizer t) {
19001899

19011900
String expr = t.nextToken("");
19021901
Value val = evaluate(expr);
1903-
if ((val != null) && (val instanceof ObjectReference)) {
1904-
ObjectReference object = (ObjectReference)val;
1902+
if (val instanceof ObjectReference object) {
19051903
object.disableCollection();
19061904
String strVal = getStringValue();
19071905
if (strVal != null) {
@@ -1929,8 +1927,7 @@ void doEnableGC(StringTokenizer t) {
19291927

19301928
String expr = t.nextToken("");
19311929
Value val = evaluate(expr);
1932-
if ((val != null) && (val instanceof ObjectReference)) {
1933-
ObjectReference object = (ObjectReference)val;
1930+
if (val instanceof ObjectReference object) {
19341931
object.enableCollection();
19351932
String strVal = getStringValue();
19361933
if (strVal != null) {

src/jdk.jdi/share/classes/com/sun/tools/jdi/BooleanValueImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,8 +40,8 @@ public class BooleanValueImpl extends PrimitiveValueImpl
4040
}
4141

4242
public boolean equals(Object obj) {
43-
if ((obj != null) && (obj instanceof BooleanValue)) {
44-
return (value == ((BooleanValue)obj).value()) &&
43+
if (obj instanceof BooleanValue other) {
44+
return (value == other.value()) &&
4545
super.equals(obj);
4646
} else {
4747
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/ByteValueImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,8 +41,8 @@ public class ByteValueImpl extends PrimitiveValueImpl
4141
}
4242

4343
public boolean equals(Object obj) {
44-
if ((obj != null) && (obj instanceof ByteValue)) {
45-
return (value == ((ByteValue)obj).value())
44+
if (obj instanceof ByteValue other) {
45+
return (value == other.value())
4646
&& super.equals(obj);
4747
} else {
4848
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/CharValueImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,8 +41,8 @@ public class CharValueImpl extends PrimitiveValueImpl
4141
}
4242

4343
public boolean equals(Object obj) {
44-
if ((obj != null) && (obj instanceof CharValue)) {
45-
return (value == ((CharValue)obj).value()) &&
44+
if (obj instanceof CharValue other) {
45+
return (value == other.value()) &&
4646
super.equals(obj);
4747
} else {
4848
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/ConnectorImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ public boolean mustSpecify() {
192192
}
193193

194194
public boolean equals(Object obj) {
195-
if ((obj != null) && (obj instanceof Connector.Argument)) {
196-
Connector.Argument other = (Connector.Argument)obj;
195+
if (obj instanceof Argument other) {
197196
return (name().equals(other.name())) &&
198197
(description().equals(other.description())) &&
199198
(mustSpecify() == other.mustSpecify()) &&

src/jdk.jdi/share/classes/com/sun/tools/jdi/DoubleValueImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,8 +40,8 @@ public class DoubleValueImpl extends PrimitiveValueImpl
4040
}
4141

4242
public boolean equals(Object obj) {
43-
if ((obj != null) && (obj instanceof DoubleValue)) {
44-
return (value == ((DoubleValue)obj).value()) &&
43+
if (obj instanceof DoubleValue other) {
44+
return (value == other.value()) &&
4545
super.equals(obj);
4646
} else {
4747
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/FieldImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public class FieldImpl extends TypeComponentImpl
4141
}
4242

4343
public boolean equals(Object obj) {
44-
if ((obj != null) && (obj instanceof FieldImpl)) {
45-
FieldImpl other = (FieldImpl)obj;
44+
if (obj instanceof FieldImpl other) {
4645
return (declaringType().equals(other.declaringType())) &&
4746
(ref() == other.ref()) &&
4847
super.equals(obj);

src/jdk.jdi/share/classes/com/sun/tools/jdi/FloatValueImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,8 +40,8 @@ public class FloatValueImpl extends PrimitiveValueImpl
4040
}
4141

4242
public boolean equals(Object obj) {
43-
if ((obj != null) && (obj instanceof FloatValue)) {
44-
return (value == ((FloatValue)obj).value()) &&
43+
if (obj instanceof FloatValue other) {
44+
return (value == other.value()) &&
4545
super.equals(obj);
4646
} else {
4747
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/IntegerValueImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,8 +40,8 @@ public class IntegerValueImpl extends PrimitiveValueImpl
4040
}
4141

4242
public boolean equals(Object obj) {
43-
if ((obj != null) && (obj instanceof IntegerValue)) {
44-
return (value == ((IntegerValue)obj).value()) &&
43+
if (obj instanceof IntegerValue other) {
44+
return (value == other.value()) &&
4545
super.equals(obj);
4646
} else {
4747
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/LocalVariableImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -66,8 +66,7 @@ public class LocalVariableImpl extends MirrorImpl
6666
}
6767

6868
public boolean equals(Object obj) {
69-
if ((obj != null) && (obj instanceof LocalVariableImpl)) {
70-
LocalVariableImpl other = (LocalVariableImpl)obj;
69+
if (obj instanceof LocalVariableImpl other) {
7170
return ((slot() == other.slot()) &&
7271
(scopeStart != null) &&
7372
(scopeStart.equals(other.scopeStart)) &&

src/jdk.jdi/share/classes/com/sun/tools/jdi/LocationImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -62,8 +62,7 @@ public class LocationImpl extends MirrorImpl implements Location {
6262
}
6363

6464
public boolean equals(Object obj) {
65-
if ((obj != null) && (obj instanceof Location)) {
66-
Location other = (Location)obj;
65+
if (obj instanceof Location other) {
6766
return (method().equals(other.method())) &&
6867
(codeIndex() == other.codeIndex()) &&
6968
super.equals(obj);

src/jdk.jdi/share/classes/com/sun/tools/jdi/LongValueImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,8 +40,8 @@ public class LongValueImpl extends PrimitiveValueImpl
4040
}
4141

4242
public boolean equals(Object obj) {
43-
if ((obj != null) && (obj instanceof LongValue)) {
44-
return (value == ((LongValue)obj).value()) &&
43+
if (obj instanceof LongValue other) {
44+
return (value == other.value()) &&
4545
super.equals(obj);
4646
} else {
4747
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/MethodImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ static MethodImpl createMethodImpl(VirtualMachine vm,
8585
}
8686

8787
public boolean equals(Object obj) {
88-
if ((obj != null) && (obj instanceof MethodImpl)) {
89-
MethodImpl other = (MethodImpl)obj;
88+
if (obj instanceof MethodImpl other) {
9089
return (declaringType().equals(other.declaringType())) &&
9190
(ref() == other.ref()) &&
9291
super.equals(obj);

src/jdk.jdi/share/classes/com/sun/tools/jdi/MirrorImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,8 +49,7 @@ public VirtualMachine virtualMachine() {
4949
}
5050

5151
public boolean equals(Object obj) {
52-
if ((obj != null) && (obj instanceof Mirror)) {
53-
Mirror other = (Mirror)obj;
52+
if (obj instanceof Mirror other) {
5453
return vm.equals(other.virtualMachine());
5554
} else {
5655
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/ObjectReferenceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ public boolean vmNotSuspended(VMAction action) {
146146
}
147147

148148
public boolean equals(Object obj) {
149-
if ((obj != null) && (obj instanceof ObjectReferenceImpl)) {
150-
ObjectReferenceImpl other = (ObjectReferenceImpl)obj;
149+
if (obj instanceof ObjectReferenceImpl other) {
151150
return (ref() == other.ref()) &&
152151
super.equals(obj);
153152
} else {

src/jdk.jdi/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ Field getFieldMirror(long ref) {
141141
}
142142

143143
public boolean equals(Object obj) {
144-
if ((obj != null) && (obj instanceof ReferenceTypeImpl)) {
145-
ReferenceTypeImpl other = (ReferenceTypeImpl)obj;
144+
if (obj instanceof ReferenceTypeImpl other) {
146145
return (ref() == other.ref()) &&
147146
(vm.equals(other.virtualMachine()));
148147
} else {

src/jdk.jdi/share/classes/com/sun/tools/jdi/ShortValueImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,8 +40,8 @@ public class ShortValueImpl extends PrimitiveValueImpl
4040
}
4141

4242
public boolean equals(Object obj) {
43-
if ((obj != null) && (obj instanceof ShortValue)) {
44-
return (value == ((ShortValue)obj).value()) &&
43+
if (obj instanceof ShortValue other) {
44+
return (value == other.value()) &&
4545
super.equals(obj);
4646
} else {
4747
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/StackFrameImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -111,8 +111,7 @@ public ThreadReference thread() {
111111
}
112112

113113
public boolean equals(Object obj) {
114-
if ((obj != null) && (obj instanceof StackFrameImpl)) {
115-
StackFrameImpl other = (StackFrameImpl)obj;
114+
if (obj instanceof StackFrameImpl other) {
116115
return (id == other.id) &&
117116
(thread().equals(other.thread())) &&
118117
(location().equals(other.location())) &&

src/jdk.jdi/share/classes/com/sun/tools/jdi/TypeImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,8 +46,7 @@ public String name() {
4646
}
4747

4848
public boolean equals(Object obj) {
49-
if ((obj != null) && (obj instanceof Type)) {
50-
Type other = (Type)obj;
49+
if (obj instanceof Type other) {
5150
return signature().equals(other.signature()) && super.equals(obj);
5251
} else {
5352
return false;

src/jdk.jdi/share/classes/com/sun/tools/jdi/VoidValueImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@ public class VoidValueImpl extends ValueImpl implements VoidValue {
3737
}
3838

3939
public boolean equals(Object obj) {
40-
return (obj != null) && (obj instanceof VoidValue) && super.equals(obj);
40+
return (obj instanceof VoidValue) && super.equals(obj);
4141
}
4242

4343
public int hashCode() {

0 commit comments

Comments
 (0)