Skip to content

Commit

Permalink
Switch order of literals to prevent NullPointerException
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeebot[bot] authored May 30, 2024
1 parent 5a4b5fa commit a900a1d
Show file tree
Hide file tree
Showing 182 changed files with 394 additions and 394 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public void init() throws IOException {
}

private BytesReference bytesImpl(BytesReference bytes) {
if (type.equals("array")) {
if ("array".equals(type)) {
return new BytesArray(bytes.toBytesRef());
}
if (type.equals("paged_bytes_array")) {
if ("paged_bytes_array".equals(type)) {
if (bytes instanceof PagedBytesReference == false) {
throw new AssertionError("expected PagedBytesReference but saw [" + bytes.getClass() + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class AggregatorBenchmark {

private static Operator operator(String grouping, String op, String dataType) {
DriverContext driverContext = driverContext();
if (grouping.equals("none")) {
if ("none".equals(grouping)) {
return new AggregationOperator(
List.of(supplier(op, dataType, 0).aggregatorFactory(AggregatorMode.SINGLE).apply(driverContext)),
driverContext
Expand Down Expand Up @@ -181,7 +181,7 @@ private static AggregatorFunctionSupplier supplier(String op, String dataType, i

private static void checkExpected(String grouping, String op, String blockType, String dataType, Page page, int opCount) {
String prefix = String.format("[%s][%s][%s] ", grouping, op, blockType);
if (grouping.equals("none")) {
if ("none".equals(grouping)) {
checkUngrouped(prefix, op, dataType, page, opCount);
return;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ private static void checkUngrouped(String prefix, String op, String dataType, Pa

private static Page page(String grouping, String blockType) {
Block dataBlock = dataBlock(blockType);
if (grouping.equals("none")) {
if ("none".equals(grouping)) {
return new Page(dataBlock);
}
List<Block> blocks = groupingBlocks(grouping, blockType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void setup() {
case "noop" -> new NoneCircuitBreakerService();
default -> throw new UnsupportedOperationException();
};
preallocateBreaker = breaker.equals("preallocate");
preallocateBreaker = "preallocate".equals(breaker);
bigArrays = new BigArrays(recycler, breakerService, "request");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void setUp() {
random = ThreadLocalRandom.current();
tdigest = tdigestFactory.create(compression);

Supplier<Double> nextRandom = () -> distribution.equals("GAUSSIAN") ? random.nextGaussian() : random.nextDouble();
Supplier<Double> nextRandom = () -> "GAUSSIAN".equals(distribution) ? random.nextGaussian() : random.nextDouble();
for (int i = 0; i < 10000; ++i) {
tdigest.add(nextRandom.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void checkFormattedMethod(DetailAST ast) {
}

final String methodName = dotAst.findFirstToken(TokenTypes.IDENT).getText();
if (methodName.equals("formatted") == false) {
if ("formatted".equals(methodName) == false) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void checkSwitchBetween(DetailAST ast) {
final DetailAST argListAst = methodCallAst.findFirstToken(TokenTypes.ELIST);
int min;
int max;
if (switchMethodName.equals("randomInt")) {
if ("randomInt".equals(switchMethodName)) {
if (argListAst.getChildCount() != 1) { // 1 arg
return;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ private void checkSwitchBetween(DetailAST ast) {
try {
int value = Integer.parseInt(exprAst.getFirstChild().getText());
if (value < min || value > max) {
if (switchMethodName.equals("randomInt")) {
if ("randomInt".equals(switchMethodName)) {
log(caseAst, SWITCH_RANDOM_INT_MSG_KEY, value, switchMethodName, max);
} else {
log(caseAst, SWITCH_BETWEEN_MSG_KEY, value, switchMethodName, min, max);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static String findOriginUrl(final Path configFile) throws IOException {
String[] pair = line.trim().split("=", 2);
props.put(pair[0].trim(), pair[1].trim());
} else {
if (line.equals("[remote \"origin\"]")) {
if ("[remote \"origin\"]".equals(line)) {
foundOrigin = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public static int findDefaultParallel(Project project) {
String name = parts.get(0);
String value = parts.get(1);
// the ID of the CPU socket
if (name.equals("physical id")) {
if ("physical id".equals(name)) {
currentID = value;
}
// Number of cores not including hyper-threading
if (name.equals("cpu cores")) {
if ("cpu cores".equals(name)) {
assert currentID.isEmpty() == false;
socketToCore.put("currentID", Integer.valueOf(value));
currentID = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ private TaskProvider<LoggedExec> createRunBwcGradleTask(
}
final String showStacktraceName = project.getGradle().getStartParameter().getShowStacktrace().name();
assert Arrays.asList("INTERNAL_EXCEPTIONS", "ALWAYS", "ALWAYS_FULL").contains(showStacktraceName);
if (showStacktraceName.equals("ALWAYS")) {
if ("ALWAYS".equals(showStacktraceName)) {
loggedExec.args("--stacktrace");
} else if (showStacktraceName.equals("ALWAYS_FULL")) {
} else if ("ALWAYS_FULL".equals(showStacktraceName)) {
loggedExec.args("--full-stacktrace");
}
if (project.getGradle().getStartParameter().isParallelProjectExecutionEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void execute(BuildFinishedFlowAction.Parameters parameters) throws FileNo
}
uploadFile.getParentFile().mkdirs();
createBuildArchiveTar(parameters.getFilteredFiles().get(), parameters.getProjectDir().get(), uploadFile);
if (uploadFile.exists() && System.getenv("BUILDKITE").equals("true")) {
if (uploadFile.exists() && "true".equals(System.getenv("BUILDKITE"))) {
String uploadFilePath = "build/" + uploadFile.getName();
try {
System.out.println("Uploading buildkite artifact: " + uploadFilePath + "...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static String pathToString(String path) {
}

static boolean isIdea() {
return System.getProperty("idea.sync.active", "false").equals("true");
return "true".equals(System.getProperty("idea.sync.active", "false"));
}

File findProjectIdPath(String currentBuildPath, Project project, ProjectComponentIdentifier id) {
Expand All @@ -220,7 +220,7 @@ File findProjectIdPath(String currentBuildPath, Project project, ProjectComponen
File includedBuildDir = project.getGradle().includedBuild(buildName).getProjectDir();
// We have to account for us renaming the :libs projects here
String[] pathSegments = id.getProjectPath().split(":");
if (pathSegments[1].equals("libs")) {
if ("libs".equals(pathSegments[1])) {
pathSegments[2] = pathSegments[2].replaceFirst("elasticsearch-", "");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void apply(Project project) {
});

String projectName = project.getName();
if (projectName.equalsIgnoreCase("integ-test-zip") == false && (projectName.contains("zip") || projectName.contains("tar"))) {
if ("integ-test-zip".equalsIgnoreCase(projectName) == false && (projectName.contains("zip") || projectName.contains("tar"))) {
project.getExtensions()
.add(
"projectLicenses",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private static List<DistributionProject> resolveArchiveProjects(File checkoutDir
String baseName = name.startsWith("oss-") ? name.substring(4, index) : name.substring(0, index);
classifier = "-" + baseName + (name.contains("aarch64") ? "-aarch64" : "-x86_64");
extension = name.substring(index + 1);
if (extension.equals("tar")) {
if ("tar".equals(extension)) {
extension += ".gz";
}
} else if (name.contains("deb")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void setupRepository(Project project, Jdk jdk) {

if (jdk.getVendor().equals(VENDOR_ADOPTIUM)) {
repoUrl = "https://api.adoptium.net/v3/binary/version/";
if (jdk.getMajor().equals("8")) {
if ("8".equals(jdk.getMajor())) {
// legacy pattern for JDK 8
artifactPattern = "jdk"
+ jdk.getBaseVersion()
Expand Down Expand Up @@ -135,7 +135,7 @@ private void setupRepository(Project project, Jdk jdk) {
}
} else if (jdk.getVendor().equals(VENDOR_ZULU)) {
repoUrl = "https://cdn.azul.com";
if (jdk.getMajor().equals("8") && isJdkOnMacOsPlatform(jdk) && jdk.getArchitecture().equals("aarch64")) {
if ("8".equals(jdk.getMajor()) && isJdkOnMacOsPlatform(jdk) && "aarch64".equals(jdk.getArchitecture())) {
artifactPattern = "zulu/bin/zulu"
+ jdk.getDistributionVersion()
+ "-ca-jdk"
Expand Down Expand Up @@ -167,12 +167,12 @@ public static NamedDomainObjectContainer<Jdk> getContainer(Project project) {

private static String dependencyNotation(Jdk jdk) {
String platformDep = isJdkOnMacOsPlatform(jdk) ? (jdk.getVendor().equals(VENDOR_ADOPTIUM) ? "mac" : "macos") : jdk.getPlatform();
String extension = jdk.getPlatform().equals("windows") ? "zip" : "tar.gz";
String extension = "windows".equals(jdk.getPlatform()) ? "zip" : "tar.gz";
return groupName(jdk) + ":" + platformDep + ":" + jdk.getBaseVersion() + ":" + jdk.getArchitecture() + "@" + extension;
}

private static boolean isJdkOnMacOsPlatform(Jdk jdk) {
return jdk.getPlatform().equals("darwin") || jdk.getPlatform().equals("mac");
return "darwin".equals(jdk.getPlatform()) || "mac".equals(jdk.getPlatform());
}

private static String groupName(Jdk jdk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void generateNotice() throws IOException {

// Find any source files with "@notice" annotated license header
for (File sourceFile : sources.getFiles()) {
boolean isPackageInfo = sourceFile.getName().equals("package-info.java");
boolean isPackageInfo = "package-info.java".equals(sourceFile.getName());
boolean foundNotice = false;
boolean inNotice = false;
StringBuilder header = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void resolveDefaultJavaToolChain() {
String bundledJdkMajorVersion = VersionProperties.getBundledJdkMajorVersion();
javaToolchainSpec.getLanguageVersion().set(JavaLanguageVersion.of(bundledJdkMajorVersion));
javaToolchainSpec.getVendor()
.set(bundledVendor.equals("openjdk") ? JvmVendorSpec.ORACLE : JvmVendorSpec.matching(bundledVendor));
.set("openjdk".equals(bundledVendor) ? JvmVendorSpec.ORACLE : JvmVendorSpec.matching(bundledVendor));
}).get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ static List<String> transformConfig(List<String> lines) {
// We don't need to explicitly define a console appender because the
// "rolling" appender will become a console appender. We also don't
// carry over "*_old" appenders
if (keyParts[1].equals("console") || keyParts[1].endsWith("_old")) {
if ("console".equals(keyParts[1]) || keyParts[1].endsWith("_old")) {
skipNext = line.endsWith("\\");
continue;
}

switch (keyParts[2]) {
case "type" -> {
if (value.equals("RollingFile")) {
if ("RollingFile".equals(value)) {
value = "Console";
}
line = key + " = " + value;
Expand All @@ -103,7 +103,7 @@ static List<String> transformConfig(List<String> lines) {
String[] parts = line.split("\\s*=\\s*");

// The root logger only needs this appender
if (parts[1].equals("rolling") == false) {
if ("rolling".equals(parts[1]) == false) {
skipNext = line.endsWith("\\");
continue;
}
Expand All @@ -112,7 +112,7 @@ static List<String> transformConfig(List<String> lines) {
String key = parts[0];
String[] keyParts = key.split("\\.");

if (keyParts[2].equals("appenderRef") && keyParts[3].endsWith("_old")) {
if ("appenderRef".equals(keyParts[2]) && keyParts[3].endsWith("_old")) {
skipNext = line.endsWith("\\");
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static void throwInvalidJavaHomeException(String description, File javaH

private static void assertMinimumCompilerVersion(JavaVersion minimumCompilerVersion) {
JavaVersion currentVersion = Jvm.current().getJavaVersion();
if (System.getProperty("idea.active", "false").equals("true") == false && minimumCompilerVersion.compareTo(currentVersion) > 0) {
if ("true".equals(System.getProperty("idea.active", "false")) == false && minimumCompilerVersion.compareTo(currentVersion) > 0) {
throw new GradleException(
"Project requires Java version of " + minimumCompilerVersion + " or newer but Gradle JAVA_HOME is " + currentVersion
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void checkModuleVersion(ModuleReference mref) {
String mVersion = mref.descriptor()
.rawVersion()
.orElseThrow(() -> new GradleException("no version found in module " + mref.descriptor().name()));
if (mVersion.equals(expectedVersion) == false) {
if (expectedVersion.equals(mVersion) == false) {
throw new GradleException("Expected version [" + expectedVersion + "], in " + mref.descriptor());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private void filterSplitPackages(Map<String, Set<String>> splitPackages) {
LOGGER.error("Package is not split: " + fqcn);
filterErrorsFound = true;
} else {
if (className.equals("*")) {
if ("*".equals(className)) {
currentClasses.clear();
} else if (currentClasses.remove(fqcn) == false) {
LOGGER.error("Class does not exist: " + fqcn);
Expand Down Expand Up @@ -316,7 +316,7 @@ private static String getPackageName(Path path) {

private String formatDependency(File dependencyFile) {
if (dependencyFile.isDirectory()) {
while (dependencyFile.getName().equals("build") == false) {
while ("build".equals(dependencyFile.getName()) == false) {
dependencyFile = dependencyFile.getParentFile();
}
String projectName = getParameters().getProjectBuildDirs().get().get(dependencyFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private Map<String, Object> generateGradleGraphPayload() {
SnykDependencyGraphBuilder builder = new SnykDependencyGraphBuilder(gradleVersion.get());
String effectiveProjectPath = projectPath.get();
builder.walkGraph(
(effectiveProjectPath.equals(":") ? projectName.get() : effectiveProjectPath),
(":".equals(effectiveProjectPath) ? projectName.get() : effectiveProjectPath),
version.get(),
firstLevelModuleDependencies
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Optional<JavaToolchainDownload> resolve(JavaToolchainRequest request) {
* 4. Aarch64 windows images are not supported
*/
private boolean requestIsSupported(JavaToolchainRequest request) {
if (VersionProperties.getBundledJdkVendor().toLowerCase().equals("openjdk") == false) {
if ("openjdk".equals(VersionProperties.getBundledJdkVendor().toLowerCase()) == false) {
return false;
}
JavaToolchainSpec javaToolchainSpec = request.getJavaToolchainSpec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void confirmPolicyExceptions(Terminal terminal, Set<String> permissions,
private static void prompt(final Terminal terminal) throws UserException {
terminal.println(Verbosity.NORMAL, "");
String text = terminal.readText("Continue with installation? [y/N]");
if (text.equalsIgnoreCase("y") == false) {
if ("y".equalsIgnoreCase(text) == false) {
throw new UserException(ExitCodes.DATA_ERROR, "installation aborted by user");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static boolean tuneG1GCInitiatingHeapOccupancyPercent(final Map<String, JvmOptio
* and {@code optionName} is not in the final JVM options.
*/
private static boolean usingG1GcWithoutCommandLineOriginOption(Map<String, JvmOption> finalJvmOptions, String optionName) {
return getRequiredOption(finalJvmOptions, "UseG1GC").getMandatoryValue().equals("true")
return "true".equals(getRequiredOption(finalJvmOptions, "UseG1GC").getMandatoryValue())
&& getRequiredOption(finalJvmOptions, optionName).isCommandLineOrigin() == false;
}

Expand Down
4 changes: 2 additions & 2 deletions libs/cli/src/main/java/org/elasticsearch/cli/Terminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ public final boolean promptYesNo(String prompt, boolean defaultYes) {
return defaultYes;
}
answer = answer.toLowerCase(Locale.ROOT);
boolean answerYes = answer.equals("y");
if (answerYes == false && answer.equals("n") == false) {
boolean answerYes = "y".equals(answer);
if (answerYes == false && "n".equals(answer) == false) {
errorPrintln("Did not understand answer '" + answer + "'");
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Path get(String first, String... more) {
* a path against an existing one!
*/
public static Path get(URI uri) {
if (uri.getScheme().equalsIgnoreCase("file")) {
if ("file".equalsIgnoreCase(uri.getScheme())) {
return DEFAULT.provider().getPath(uri);
} else {
return Paths.get(uri);
Expand Down
Loading

0 comments on commit a900a1d

Please sign in to comment.