From c7dbb21b773431fe3aa2d021e5bf6d663abcd2fd Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 22 Jun 2026 23:27:27 +0200 Subject: [PATCH] Fixed more ternary concatenation bugs Eval order is from left to right which can lead to undesired effects when the right side has a ternary operator. This puts the ternary operation in braces (or avoids the situation by other means) --- .../customizers/common/TextMapping.java | 4 ++-- .../optional/TomcatIncrementalDeployment.java | 2 +- .../modules/css/visual/PropertyValuesEditor.java | 2 +- .../spi/project/support/ant/ReferenceHelper.java | 2 +- .../model/visitor/FindUsageVisitorTest.java | 2 +- .../org/netbeans/api/java/platform/Profile.java | 16 ++++++++++------ .../netbeans/modules/javadoc/hints/Analyzer.java | 7 ++++++- .../editor/parser/astnodes/CaseDeclaration.java | 2 +- .../editor/parser/astnodes/EnumDeclaration.java | 2 +- 9 files changed, 24 insertions(+), 15 deletions(-) diff --git a/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/TextMapping.java b/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/TextMapping.java index 96203073f436..8e68150ce79d 100644 --- a/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/TextMapping.java +++ b/enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/TextMapping.java @@ -75,8 +75,8 @@ public boolean equals(Object obj) { @Override public int hashCode() { int hash = 7; - hash = 17 * hash + this.xmlText != null ? this.xmlText.hashCode() : 0; - hash = 17 * hash + this.displayText != null ? this.displayText.hashCode() : 0; + hash = 17 * hash + (this.xmlText != null ? this.xmlText.hashCode() : 0); + hash = 17 * hash + (this.displayText != null ? this.displayText.hashCode() : 0); return hash; } diff --git a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/optional/TomcatIncrementalDeployment.java b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/optional/TomcatIncrementalDeployment.java index e85bac4eb90b..a2e9f514bfdc 100644 --- a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/optional/TomcatIncrementalDeployment.java +++ b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/optional/TomcatIncrementalDeployment.java @@ -83,7 +83,7 @@ public File getDirectoryForNewApplication (Target target, J2eeModule module, Mod return f; }*/ } - throw new IllegalArgumentException ("ModuleType:" + module == null ? null : module.getModuleType() + " Configuration:"+configuration); //NOI18N + throw new IllegalArgumentException("ModuleType:" + (module == null ? null : module.getModuleType()) + " Configuration:" + configuration); //NOI18N } @Override diff --git a/ide/css.visual/src/org/netbeans/modules/css/visual/PropertyValuesEditor.java b/ide/css.visual/src/org/netbeans/modules/css/visual/PropertyValuesEditor.java index 4309621aa3dd..cd88b678c9a7 100644 --- a/ide/css.visual/src/org/netbeans/modules/css/visual/PropertyValuesEditor.java +++ b/ide/css.visual/src/org/netbeans/modules/css/visual/PropertyValuesEditor.java @@ -278,7 +278,7 @@ private void editingCancelled() { @Override public String toString() { - return getClass().getSimpleName() + "; property: " + pmodel != null ? pmodel.getName() : "?"; //NOI18N + return getClass().getSimpleName() + "; property: " + (pmodel != null ? pmodel.getName() : "?"); //NOI18N } @Override diff --git a/ide/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java b/ide/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java index b01f800a1b58..d6f4afe101e8 100644 --- a/ide/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java +++ b/ide/project.ant/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java @@ -1918,7 +1918,7 @@ private void upgrade() { public @Override String toString() { return "ReferenceHelper.RawReference<" + foreignProjectName + "," + - artifactType + "," + newScriptLocation != null ? newScriptLocation : scriptLocation + + artifactType + "," + (newScriptLocation != null ? newScriptLocation : scriptLocation) + "," + targetName + "," + cleanTargetName + "," + artifactID + ">"; // NOI18N } diff --git a/ide/xml.schema.model/test/unit/src/org/netbeans/modules/xml/schema/model/visitor/FindUsageVisitorTest.java b/ide/xml.schema.model/test/unit/src/org/netbeans/modules/xml/schema/model/visitor/FindUsageVisitorTest.java index 2d87ef908936..47195c9606bd 100644 --- a/ide/xml.schema.model/test/unit/src/org/netbeans/modules/xml/schema/model/visitor/FindUsageVisitorTest.java +++ b/ide/xml.schema.model/test/unit/src/org/netbeans/modules/xml/schema/model/visitor/FindUsageVisitorTest.java @@ -110,7 +110,7 @@ public static Test suite() { public int findUsageCountForItem(NamedReferenceable ref) { long startTime = System.currentTimeMillis(); - System.out.println("Finding Usage for " + ref.getName() == null? ref : ref.getName()); + System.out.println("Finding Usage for " + (ref.getName() == null ? ref : ref.getName())); FindUsageVisitor usage = new FindUsageVisitor(); Preview preview = usage.findUsages(Collections.singletonList(schema), ref); System.out.println(preview.getUsages().size() + " occurances found!!!"); diff --git a/java/java.platform/src/org/netbeans/api/java/platform/Profile.java b/java/java.platform/src/org/netbeans/api/java/platform/Profile.java index 9fed16d1d74a..b47e5402de70 100644 --- a/java/java.platform/src/org/netbeans/api/java/platform/Profile.java +++ b/java/java.platform/src/org/netbeans/api/java/platform/Profile.java @@ -18,6 +18,7 @@ */ package org.netbeans.api.java.platform; +import java.util.Objects; import org.openide.modules.SpecificationVersion; /** @@ -25,8 +26,8 @@ */ public class Profile { - private String name; - private SpecificationVersion version; + private final String name; + private final SpecificationVersion version; /** * Creates new Profile @@ -55,7 +56,8 @@ public final SpecificationVersion getVersion () { } - public int hashCode () { + @Override + public int hashCode() { int hc = 0; if (name != null) hc = name.hashCode() << 16; @@ -64,7 +66,8 @@ public int hashCode () { return hc; } - public boolean equals (Object other) { + @Override + public boolean equals(Object other) { if (other instanceof Profile) { Profile op = (Profile) other; return this.name == null ? op.name == null : this.name.equals(op.name) && @@ -74,10 +77,11 @@ public boolean equals (Object other) { return false; } - public String toString () { + @Override + public String toString() { String str; str = this.name == null ? "" : this.name; - str += " " + this.version == null ? "" : this.version.toString(); // NOI18N + str += " " + Objects.toString(this.version, ""); // NOI18N return str; } } diff --git a/java/javadoc/src/org/netbeans/modules/javadoc/hints/Analyzer.java b/java/javadoc/src/org/netbeans/modules/javadoc/hints/Analyzer.java index 548b65ae1563..c786c5077821 100644 --- a/java/javadoc/src/org/netbeans/modules/javadoc/hints/Analyzer.java +++ b/java/javadoc/src/org/netbeans/modules/javadoc/hints/Analyzer.java @@ -657,7 +657,12 @@ public Void visitThrows(ThrowsTree tree, List errors) { final TypeElement errorEl = elements.getTypeElement("java.lang.Error"); final TypeElement runtimeEl = elements.getTypeElement("java.lang.RuntimeException"); if(throwableEl == null || errorEl == null || runtimeEl == null) { - LOG.warning("Broken java-platform, cannot resolve " + throwableEl == null? "java.lang.Throwable" : errorEl == null? "java.lang.Error" : "java.lang.RuntimeException"); //NOI18N + LOG.log(Level.WARNING, "Broken java-platform, cannot resolve {0}", + throwableEl == null + ? "java.lang.Throwable" + : errorEl == null + ? "java.lang.Error" + : "java.lang.RuntimeException"); return null; } TypeMirror throwable = throwableEl.asType(); diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/CaseDeclaration.java b/php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/CaseDeclaration.java index 9a1ce80aa94d..0287db1cdf5b 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/CaseDeclaration.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/CaseDeclaration.java @@ -86,7 +86,7 @@ public void accept(Visitor visitor) { public String toString() { StringBuilder sbAttributes = new StringBuilder(); getAttributes().forEach(attribute -> sbAttributes.append(attribute).append(" ")); // NOI18N - return sbAttributes.toString() + "case" + name + initializer == null ? "" : " = " + initializer; // NOI18N + return sbAttributes.toString() + "case" + name + (initializer == null ? "" : " = " + initializer); // NOI18N } } diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/EnumDeclaration.java b/php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/EnumDeclaration.java index 9fe28995caff..506378f93187 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/EnumDeclaration.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/EnumDeclaration.java @@ -104,6 +104,6 @@ public String toString() { for (Expression expression : getInterfaces()) { sb.append(expression).append(","); // NOI18N } - return sbAttributes.toString() + "enum " + getName() + backingType == null ? "" : ": " + backingType + " implements " + sb + getBody(); // NOI18N + return sbAttributes.toString() + "enum " + getName() + (backingType == null ? "" : ": " + backingType) + " implements " + sb + getBody(); // NOI18N } }