8274232: Cleanup unnecessary null comparison before instanceof check in jdk.jdi

Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
Andrey Turbanov 2021-11-15 19:14:17 +00:00 committed by Chris Plummer
parent 1830b8da90
commit db0c8d5227
20 changed files with 46 additions and 59 deletions

View File

@ -708,9 +708,9 @@ class Commands {
} }
String expr = t.nextToken(""); String expr = t.nextToken("");
Value val = evaluate(expr); Value val = evaluate(expr);
if ((val != null) && (val instanceof ObjectReference)) { if (val instanceof ObjectReference object) {
try { try {
thread.stop((ObjectReference)val); thread.stop(object);
MessageOutput.println("killed", thread.toString()); MessageOutput.println("killed", thread.toString());
} catch (InvalidTypeException e) { } catch (InvalidTypeException e) {
MessageOutput.println("Invalid exception object"); MessageOutput.println("Invalid exception object");
@ -1804,8 +1804,7 @@ class Commands {
Value val = evaluate(expr); Value val = evaluate(expr);
try { try {
if ((val != null) && (val instanceof ObjectReference)) { if (val instanceof ObjectReference object) {
ObjectReference object = (ObjectReference)val;
String strVal = getStringValue(); String strVal = getStringValue();
if (strVal != null) { if (strVal != null) {
MessageOutput.println("Monitor information for expr", MessageOutput.println("Monitor information for expr",
@ -1900,8 +1899,7 @@ class Commands {
String expr = t.nextToken(""); String expr = t.nextToken("");
Value val = evaluate(expr); Value val = evaluate(expr);
if ((val != null) && (val instanceof ObjectReference)) { if (val instanceof ObjectReference object) {
ObjectReference object = (ObjectReference)val;
object.disableCollection(); object.disableCollection();
String strVal = getStringValue(); String strVal = getStringValue();
if (strVal != null) { if (strVal != null) {
@ -1929,8 +1927,7 @@ class Commands {
String expr = t.nextToken(""); String expr = t.nextToken("");
Value val = evaluate(expr); Value val = evaluate(expr);
if ((val != null) && (val instanceof ObjectReference)) { if (val instanceof ObjectReference object) {
ObjectReference object = (ObjectReference)val;
object.enableCollection(); object.enableCollection();
String strVal = getStringValue(); String strVal = getStringValue();
if (strVal != null) { if (strVal != null) {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof BooleanValue)) { if (obj instanceof BooleanValue other) {
return (value == ((BooleanValue)obj).value()) && return (value == other.value()) &&
super.equals(obj); super.equals(obj);
} else { } else {
return false; return false;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ByteValue)) { if (obj instanceof ByteValue other) {
return (value == ((ByteValue)obj).value()) return (value == other.value())
&& super.equals(obj); && super.equals(obj);
} else { } else {
return false; return false;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof CharValue)) { if (obj instanceof CharValue other) {
return (value == ((CharValue)obj).value()) && return (value == other.value()) &&
super.equals(obj); super.equals(obj);
} else { } else {
return false; return false;

View File

@ -192,8 +192,7 @@ abstract class ConnectorImpl implements Connector {
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Connector.Argument)) { if (obj instanceof Argument other) {
Connector.Argument other = (Connector.Argument)obj;
return (name().equals(other.name())) && return (name().equals(other.name())) &&
(description().equals(other.description())) && (description().equals(other.description())) &&
(mustSpecify() == other.mustSpecify()) && (mustSpecify() == other.mustSpecify()) &&

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof DoubleValue)) { if (obj instanceof DoubleValue other) {
return (value == ((DoubleValue)obj).value()) && return (value == other.value()) &&
super.equals(obj); super.equals(obj);
} else { } else {
return false; return false;

View File

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

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof FloatValue)) { if (obj instanceof FloatValue other) {
return (value == ((FloatValue)obj).value()) && return (value == other.value()) &&
super.equals(obj); super.equals(obj);
} else { } else {
return false; return false;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof IntegerValue)) { if (obj instanceof IntegerValue other) {
return (value == ((IntegerValue)obj).value()) && return (value == other.value()) &&
super.equals(obj); super.equals(obj);
} else { } else {
return false; return false;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof LocalVariableImpl)) { if (obj instanceof LocalVariableImpl other) {
LocalVariableImpl other = (LocalVariableImpl)obj;
return ((slot() == other.slot()) && return ((slot() == other.slot()) &&
(scopeStart != null) && (scopeStart != null) &&
(scopeStart.equals(other.scopeStart)) && (scopeStart.equals(other.scopeStart)) &&

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Location)) { if (obj instanceof Location other) {
Location other = (Location)obj;
return (method().equals(other.method())) && return (method().equals(other.method())) &&
(codeIndex() == other.codeIndex()) && (codeIndex() == other.codeIndex()) &&
super.equals(obj); super.equals(obj);

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof LongValue)) { if (obj instanceof LongValue other) {
return (value == ((LongValue)obj).value()) && return (value == other.value()) &&
super.equals(obj); super.equals(obj);
} else { } else {
return false; return false;

View File

@ -85,8 +85,7 @@ public abstract class MethodImpl extends TypeComponentImpl
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof MethodImpl)) { if (obj instanceof MethodImpl other) {
MethodImpl other = (MethodImpl)obj;
return (declaringType().equals(other.declaringType())) && return (declaringType().equals(other.declaringType())) &&
(ref() == other.ref()) && (ref() == other.ref()) &&
super.equals(obj); super.equals(obj);

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -49,8 +49,7 @@ abstract class MirrorImpl extends Object implements Mirror {
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Mirror)) { if (obj instanceof Mirror other) {
Mirror other = (Mirror)obj;
return vm.equals(other.virtualMachine()); return vm.equals(other.virtualMachine());
} else { } else {
return false; return false;

View File

@ -146,8 +146,7 @@ public class ObjectReferenceImpl extends ValueImpl
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ObjectReferenceImpl)) { if (obj instanceof ObjectReferenceImpl other) {
ObjectReferenceImpl other = (ObjectReferenceImpl)obj;
return (ref() == other.ref()) && return (ref() == other.ref()) &&
super.equals(obj); super.equals(obj);
} else { } else {

View File

@ -141,8 +141,7 @@ public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceTyp
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ReferenceTypeImpl)) { if (obj instanceof ReferenceTypeImpl other) {
ReferenceTypeImpl other = (ReferenceTypeImpl)obj;
return (ref() == other.ref()) && return (ref() == other.ref()) &&
(vm.equals(other.virtualMachine())); (vm.equals(other.virtualMachine()));
} else { } else {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof ShortValue)) { if (obj instanceof ShortValue other) {
return (value == ((ShortValue)obj).value()) && return (value == other.value()) &&
super.equals(obj); super.equals(obj);
} else { } else {
return false; return false;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -111,8 +111,7 @@ public class StackFrameImpl extends MirrorImpl
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof StackFrameImpl)) { if (obj instanceof StackFrameImpl other) {
StackFrameImpl other = (StackFrameImpl)obj;
return (id == other.id) && return (id == other.id) &&
(thread().equals(other.thread())) && (thread().equals(other.thread())) &&
(location().equals(other.location())) && (location().equals(other.location())) &&

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -46,8 +46,7 @@ public abstract class TypeImpl extends MirrorImpl implements Type {
} }
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Type)) { if (obj instanceof Type other) {
Type other = (Type)obj;
return signature().equals(other.signature()) && super.equals(obj); return signature().equals(other.signature()) && super.equals(obj);
} else { } else {
return false; return false;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public boolean equals(Object obj) {
return (obj != null) && (obj instanceof VoidValue) && super.equals(obj); return (obj instanceof VoidValue) && super.equals(obj);
} }
public int hashCode() { public int hashCode() {