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.
*
* 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 sval2 = ((StringValueExp)val2).getValue();
int cmp = sval1.compareTo(sval2);
switch (relOp) {
case Query.GT:
return sval1.compareTo(sval2) > 0;
return cmp > 0;
case Query.LT:
return sval1.compareTo(sval2) < 0;
return cmp < 0;
case Query.GE:
return sval1.compareTo(sval2) >= 0;
return cmp >= 0;
case Query.LE:
return sval1.compareTo(sval2) <= 0;
return cmp <= 0;
case Query.EQ:
return sval1.compareTo(sval2) == 0;
return cmp == 0;
}
}

View File

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