8274168: Avoid String.compareTo == 0 to check String equality in java.management

Reviewed-by: sspitsyn, dfuchs, cjplummer, dholmes
This commit is contained in:
Andrey Turbanov 2021-11-16 11:14:37 +00:00 committed by Serguei Spitsyn
parent 20f3872d1c
commit a9cb8bdbaa
2 changed files with 17 additions and 29 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2008, 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. * 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
@ -167,17 +167,18 @@ class BinaryRelQueryExp extends QueryEval implements QueryExp {
String sval1 = ((StringValueExp)val1).getValue(); String sval1 = ((StringValueExp)val1).getValue();
String sval2 = ((StringValueExp)val2).getValue(); String sval2 = ((StringValueExp)val2).getValue();
int cmp = sval1.compareTo(sval2);
switch (relOp) { switch (relOp) {
case Query.GT: case Query.GT:
return sval1.compareTo(sval2) > 0; return cmp > 0;
case Query.LT: case Query.LT:
return sval1.compareTo(sval2) < 0; return cmp < 0;
case Query.GE: case Query.GE:
return sval1.compareTo(sval2) >= 0; return cmp >= 0;
case Query.LE: case Query.LE:
return sval1.compareTo(sval2) <= 0; return cmp <= 0;
case Query.EQ: case Query.EQ:
return sval1.compareTo(sval2) == 0; return cmp == 0;
} }
} }

View File

@ -25,16 +25,12 @@
package javax.management.loading; package javax.management.loading;
// Java import
import com.sun.jmx.defaults.JmxProperties;
import com.sun.jmx.defaults.ServiceName; import com.sun.jmx.defaults.ServiceName;
import com.sun.jmx.remote.util.EnvHelp; import com.sun.jmx.remote.util.EnvHelp;
import java.io.Externalizable; import java.io.Externalizable;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.ObjectInput; import java.io.ObjectInput;
@ -71,7 +67,6 @@ import javax.management.ReflectionException;
import static com.sun.jmx.defaults.JmxProperties.MLET_LIB_DIR; import static com.sun.jmx.defaults.JmxProperties.MLET_LIB_DIR;
import static com.sun.jmx.defaults.JmxProperties.MLET_LOGGER; import static com.sun.jmx.defaults.JmxProperties.MLET_LOGGER;
import com.sun.jmx.defaults.ServiceName;
import javax.management.ServiceNotFoundException; import javax.management.ServiceNotFoundException;
/** /**
@ -1270,24 +1265,16 @@ public class MLet extends java.net.URLClassLoader
MLET_LOGGER.log(Level.DEBUG, "Got unexpected exception", e); MLET_LOGGER.log(Level.DEBUG, "Got unexpected exception", e);
} }
} }
if (type.compareTo("java.lang.Boolean") == 0) return switch (type) {
return Boolean.valueOf(param); case "java.lang.Boolean" -> Boolean.valueOf(param);
if (type.compareTo("java.lang.Byte") == 0) case "java.lang.Byte" -> Byte.valueOf(param);
return Byte.valueOf(param); case "java.lang.Short" -> Short.valueOf(param);
if (type.compareTo("java.lang.Short") == 0) case "java.lang.Long" -> Long.valueOf(param);
return Short.valueOf(param); case "java.lang.Integer" -> Integer.valueOf(param);
if (type.compareTo("java.lang.Long") == 0) case "java.lang.Float" -> Float.valueOf(param);
return Long.valueOf(param); case "java.lang.Double" -> Double.valueOf(param);
if (type.compareTo("java.lang.Integer") == 0) default -> param;
return Integer.valueOf(param); };
if (type.compareTo("java.lang.Float") == 0)
return Float.valueOf(param);
if (type.compareTo("java.lang.Double") == 0)
return Double.valueOf(param);
if (type.compareTo("java.lang.String") == 0)
return param;
return param;
} }
@SuppressWarnings("removal") @SuppressWarnings("removal")