Skip to content
Permalink
Browse files
8274232: Cleanup unnecessary null comparison before instanceof check …
…in jdk.jdi

Reviewed-by: cjplummer, sspitsyn
  • Loading branch information
turbanoff authored and plummercj committed Nov 15, 2021
1 parent 1830b8d commit db0c8d522704d2e12bce4ebeb9297b57e3789f4f
Showing 20 changed files with 46 additions and 59 deletions.
@@ -708,9 +708,9 @@ void doKill(ThreadReference thread, StringTokenizer t) {
}
String expr = t.nextToken("");
Value val = evaluate(expr);
if ((val != null) && (val instanceof ObjectReference)) {
if (val instanceof ObjectReference object) {
try {
thread.stop((ObjectReference)val);
thread.stop(object);
MessageOutput.println("killed", thread.toString());
} catch (InvalidTypeException e) {
MessageOutput.println("Invalid exception object");
@@ -1804,8 +1804,7 @@ void doLock(StringTokenizer t) {
Value val = evaluate(expr);

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

String expr = t.nextToken("");
Value val = evaluate(expr);
if ((val != null) && (val instanceof ObjectReference)) {
ObjectReference object = (ObjectReference)val;
if (val instanceof ObjectReference object) {
object.disableCollection();
String strVal = getStringValue();
if (strVal != null) {
@@ -1929,8 +1927,7 @@ void doEnableGC(StringTokenizer t) {

String expr = t.nextToken("");
Value val = evaluate(expr);
if ((val != null) && (val instanceof ObjectReference)) {
ObjectReference object = (ObjectReference)val;
if (val instanceof ObjectReference object) {
object.enableCollection();
String strVal = getStringValue();
if (strVal != null) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -40,8 +40,8 @@ public class BooleanValueImpl extends PrimitiveValueImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof BooleanValue)) {
return (value == ((BooleanValue)obj).value()) &&
if (obj instanceof BooleanValue other) {
return (value == other.value()) &&
super.equals(obj);
} else {
return false;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -41,8 +41,8 @@ public class ByteValueImpl extends PrimitiveValueImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ByteValue)) {
return (value == ((ByteValue)obj).value())
if (obj instanceof ByteValue other) {
return (value == other.value())
&& super.equals(obj);
} else {
return false;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -41,8 +41,8 @@ public class CharValueImpl extends PrimitiveValueImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof CharValue)) {
return (value == ((CharValue)obj).value()) &&
if (obj instanceof CharValue other) {
return (value == other.value()) &&
super.equals(obj);
} else {
return false;
@@ -192,8 +192,7 @@ public boolean mustSpecify() {
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Connector.Argument)) {
Connector.Argument other = (Connector.Argument)obj;
if (obj instanceof Argument other) {
return (name().equals(other.name())) &&
(description().equals(other.description())) &&
(mustSpecify() == other.mustSpecify()) &&
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -40,8 +40,8 @@ public class DoubleValueImpl extends PrimitiveValueImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof DoubleValue)) {
return (value == ((DoubleValue)obj).value()) &&
if (obj instanceof DoubleValue other) {
return (value == other.value()) &&
super.equals(obj);
} else {
return false;
@@ -41,8 +41,7 @@ public class FieldImpl extends TypeComponentImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof FieldImpl)) {
FieldImpl other = (FieldImpl)obj;
if (obj instanceof FieldImpl other) {
return (declaringType().equals(other.declaringType())) &&
(ref() == other.ref()) &&
super.equals(obj);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -40,8 +40,8 @@ public class FloatValueImpl extends PrimitiveValueImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof FloatValue)) {
return (value == ((FloatValue)obj).value()) &&
if (obj instanceof FloatValue other) {
return (value == other.value()) &&
super.equals(obj);
} else {
return false;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -40,8 +40,8 @@ public class IntegerValueImpl extends PrimitiveValueImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof IntegerValue)) {
return (value == ((IntegerValue)obj).value()) &&
if (obj instanceof IntegerValue other) {
return (value == other.value()) &&
super.equals(obj);
} else {
return false;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -66,8 +66,7 @@ public class LocalVariableImpl extends MirrorImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof LocalVariableImpl)) {
LocalVariableImpl other = (LocalVariableImpl)obj;
if (obj instanceof LocalVariableImpl other) {
return ((slot() == other.slot()) &&
(scopeStart != null) &&
(scopeStart.equals(other.scopeStart)) &&
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -62,8 +62,7 @@ public class LocationImpl extends MirrorImpl implements Location {
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Location)) {
Location other = (Location)obj;
if (obj instanceof Location other) {
return (method().equals(other.method())) &&
(codeIndex() == other.codeIndex()) &&
super.equals(obj);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -40,8 +40,8 @@ public class LongValueImpl extends PrimitiveValueImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof LongValue)) {
return (value == ((LongValue)obj).value()) &&
if (obj instanceof LongValue other) {
return (value == other.value()) &&
super.equals(obj);
} else {
return false;
@@ -85,8 +85,7 @@ static MethodImpl createMethodImpl(VirtualMachine vm,
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof MethodImpl)) {
MethodImpl other = (MethodImpl)obj;
if (obj instanceof MethodImpl other) {
return (declaringType().equals(other.declaringType())) &&
(ref() == other.ref()) &&
super.equals(obj);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -49,8 +49,7 @@ public VirtualMachine virtualMachine() {
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Mirror)) {
Mirror other = (Mirror)obj;
if (obj instanceof Mirror other) {
return vm.equals(other.virtualMachine());
} else {
return false;
@@ -146,8 +146,7 @@ public boolean vmNotSuspended(VMAction action) {
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ObjectReferenceImpl)) {
ObjectReferenceImpl other = (ObjectReferenceImpl)obj;
if (obj instanceof ObjectReferenceImpl other) {
return (ref() == other.ref()) &&
super.equals(obj);
} else {
@@ -141,8 +141,7 @@ Field getFieldMirror(long ref) {
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ReferenceTypeImpl)) {
ReferenceTypeImpl other = (ReferenceTypeImpl)obj;
if (obj instanceof ReferenceTypeImpl other) {
return (ref() == other.ref()) &&
(vm.equals(other.virtualMachine()));
} else {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -40,8 +40,8 @@ public class ShortValueImpl extends PrimitiveValueImpl
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ShortValue)) {
return (value == ((ShortValue)obj).value()) &&
if (obj instanceof ShortValue other) {
return (value == other.value()) &&
super.equals(obj);
} else {
return false;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -111,8 +111,7 @@ public ThreadReference thread() {
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof StackFrameImpl)) {
StackFrameImpl other = (StackFrameImpl)obj;
if (obj instanceof StackFrameImpl other) {
return (id == other.id) &&
(thread().equals(other.thread())) &&
(location().equals(other.location())) &&
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -46,8 +46,7 @@ public String name() {
}

public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Type)) {
Type other = (Type)obj;
if (obj instanceof Type other) {
return signature().equals(other.signature()) && super.equals(obj);
} else {
return false;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 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
@@ -37,7 +37,7 @@ public class VoidValueImpl extends ValueImpl implements VoidValue {
}

public boolean equals(Object obj) {
return (obj != null) && (obj instanceof VoidValue) && super.equals(obj);
return (obj instanceof VoidValue) && super.equals(obj);
}

public int hashCode() {

1 comment on commit db0c8d5

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on db0c8d5 Nov 15, 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.