Skip to content

Commit

Permalink
Cleanup: use Boolean.parseBoolean for string-to-boolean conversion (s…
Browse files Browse the repository at this point in the history
…potbugs#3217)

* Use "Boolean.parseBoolean" for string-to-boolean conversion

* add changelog entry

* fix merge
  • Loading branch information
JuditKnoll authored Dec 5, 2024
1 parent 811962e commit 3a5d330
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2.
- Use method references instead of lambdas where possible ([#3179](https://github.com/spotbugs/spotbugs/pull/3179))
- Move default clauses to the end of switches ([#3222](https://github.com/spotbugs/spotbugs/pull/3222))
- Remove unnecessary throws declarations ([#3220](https://github.com/spotbugs/spotbugs/pull/3220))
- Use `Boolean.parseBoolean()` for string-to-boolean conversion. ([#3217](https://github.com/spotbugs/spotbugs/pull/3217))

### Changed
- Bump up Java version to 11
Expand Down
12 changes: 6 additions & 6 deletions eclipsePlugin/src/de/tobject/findbugs/FindbugsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,27 +473,27 @@ public void configurePluginDebugOptions() {
if (isDebugging()) {
// debugging for the plugin itself
String option = Platform.getDebugOption(PLUGIN_DEBUG);
FindbugsPlugin.DEBUG = Boolean.valueOf(option).booleanValue();
FindbugsPlugin.DEBUG = Boolean.parseBoolean(option);

// debugging for the builder and friends
option = Platform.getDebugOption(BUILDER_DEBUG);
FindBugsBuilder.DEBUG = Boolean.valueOf(option).booleanValue();
FindBugsBuilder.DEBUG = Boolean.parseBoolean(option);
FindBugsWorker.DEBUG = FindBugsBuilder.DEBUG;

// debugging for the nature
option = Platform.getDebugOption(NATURE_DEBUG);
FindBugsNature.DEBUG = Boolean.valueOf(option).booleanValue();
FindBugsNature.DEBUG = Boolean.parseBoolean(option);

// debugging for the reporter
option = Platform.getDebugOption(REPORTER_DEBUG);
Reporter.DEBUG = Boolean.valueOf(option).booleanValue();
Reporter.DEBUG = Boolean.parseBoolean(option);

// debugging for the content provider
option = Platform.getDebugOption(CONTENT_DEBUG);
BugContentProvider.DEBUG = Boolean.valueOf(option).booleanValue();
BugContentProvider.DEBUG = Boolean.parseBoolean(option);

option = Platform.getDebugOption(PROFILER_DEBUG);
if (Boolean.valueOf(option).booleanValue()) {
if (Boolean.parseBoolean(option)) {
System.setProperty("profiler.report", "true");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public String getValue() {
* @return value of property as a boolean
*/
public boolean getValueAsBoolean() {
return Boolean.valueOf(getValue()).booleanValue();
return Boolean.parseBoolean(getValue());
}

/**
Expand Down
14 changes: 7 additions & 7 deletions spotbugs/src/main/java/edu/umd/cs/findbugs/PluginLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ private void loadPluginComponents()

try {
String propertiesLocation = componentNode.valueOf("@properties");
boolean disabled = Boolean.valueOf(componentNode.valueOf("@disabled"));
boolean disabled = Boolean.parseBoolean(componentNode.valueOf("@disabled"));

Node filterMessageNode = findMessageNode(messageCollectionList,
"/MessageCollection/PluginComponent[@id='" + componentId + "']",
Expand Down Expand Up @@ -822,7 +822,7 @@ private void loadPluginComponents()
+ " loaded from " + loadedFrom);
}
String kind = main.valueOf("@kind");
boolean analysis = Boolean.valueOf(main.valueOf("@analysis"));
boolean analysis = Boolean.parseBoolean(main.valueOf("@analysis"));
Element mainMessageNode = (Element) findMessageNode(messageCollectionList,
"/MessageCollection/FindBugsMain[@cmd='" + cmd
// + " and @class='" + className
Expand Down Expand Up @@ -867,7 +867,7 @@ private void loadPluginComponents()
}
DetectorFactory factory = new DetectorFactory(plugin, className, detectorClass, !"true".equals(disabled), speed,
reports, requireJRE);
if (Boolean.valueOf(hidden).booleanValue()) {
if (Boolean.parseBoolean(hidden)) {
factory.setHidden(true);
}
factory.setPositionSpecifiedInPluginDescriptor(detectorCount++);
Expand Down Expand Up @@ -927,7 +927,7 @@ private void loadPluginComponents()
}
BugCategory bc = plugin.addOrCreateBugCategory(key);

boolean hidden = Boolean.valueOf(categoryNode.valueOf("@hidden"));
boolean hidden = Boolean.parseBoolean(categoryNode.valueOf("@hidden"));
if (hidden) {
bc.setHidden(hidden);
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ private void loadPluginComponents()

try {
String deprecatedStr = bugPatternNode.valueOf("@deprecated");
boolean deprecated = !deprecatedStr.isEmpty() && Boolean.valueOf(deprecatedStr).booleanValue();
boolean deprecated = !deprecatedStr.isEmpty() && Boolean.parseBoolean(deprecatedStr);
if (deprecated) {
bugPattern.setDeprecated(deprecated);
}
Expand Down Expand Up @@ -1288,7 +1288,7 @@ private DetectorFactorySelector getConstraintSelector(Element constraintElement,

node = constraintElement.selectSingleNode("./" + singleDetectorElementName + "Category");
if (node != null) {
boolean spanPlugins = Boolean.valueOf(node.valueOf("@spanplugins")).booleanValue();
boolean spanPlugins = Boolean.parseBoolean(node.valueOf("@spanplugins"));

String categoryName = node.valueOf("@name");
if (!"".equals(categoryName)) {
Expand All @@ -1307,7 +1307,7 @@ private DetectorFactorySelector getConstraintSelector(Element constraintElement,

node = constraintElement.selectSingleNode("./" + singleDetectorElementName + "Subtypes");
if (node != null) {
boolean spanPlugins = Boolean.valueOf(node.valueOf("@spanplugins")).booleanValue();
boolean spanPlugins = Boolean.parseBoolean(node.valueOf("@spanplugins"));

String superName = node.valueOf("@super");
if (!"".equals(superName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected void handleOption(String option, String optionExtraPart) {
} else if ("-quiet".equals(option)) {
quiet = true;
} else if ("-nested".equals(option)) {
scanNestedArchives = "".equals(optionExtraPart) || Boolean.valueOf(optionExtraPart).booleanValue();
scanNestedArchives = "".equals(optionExtraPart) || Boolean.parseBoolean(optionExtraPart);
} else if ("-exitcode".equals(option)) {
setExitCode = true;
} else if ("-auxclasspathFromInput".equals(option)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static ProjectFilterSettings fromEncodedString(String s) {
displayFalseWarnings = s;
s = "";
}
result.setDisplayFalseWarnings(Boolean.valueOf(displayFalseWarnings).booleanValue());
result.setDisplayFalseWarnings(Boolean.parseBoolean(displayFalseWarnings));
}

if (!s.isEmpty()) {
Expand Down Expand Up @@ -282,7 +282,7 @@ public boolean displayWarning(BugInstance bugInstance) {
}

if (!displayFalseWarnings) {
boolean isFalseWarning = !Boolean.valueOf(bugInstance.getProperty(BugProperty.IS_BUG, "true")).booleanValue();
boolean isFalseWarning = !Boolean.parseBoolean(bugInstance.getProperty(BugProperty.IS_BUG, "true"));
if (isFalseWarning) {
return false;
}
Expand Down

0 comments on commit 3a5d330

Please sign in to comment.