Skip to content

Commit

Permalink
HTML report is not generated on the Windows platform (#1842)
Browse files Browse the repository at this point in the history
* chore: specify the eol setting to stabilize spotless result

refs diffplug/spotless#39 (comment)

* chore: replace CRLF with LF

* build: stabilize the build even with old JVM

* test: reproduce the reported problem with unit test

* fix: report without extra option cannot be created

* chore: apply spotless
  • Loading branch information
KengoTODA committed Dec 6, 2021
1 parent d9df81c commit ff31e03
Show file tree
Hide file tree
Showing 17 changed files with 447 additions and 378 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
gradlew linguist-generated=true
gradlew.bat linguist-generated=true
* text eol=lf
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2.
## Unreleased - 2021-??-??
### Fixed
- Ant task does not produce XML anymore ([#1827](https://github.com/spotbugs/spotbugs/issues/1827))
- Reports cannot be created on Windows platform ([#1842](https://github.com/spotbugs/spotbugs/pull/1842))

## 4.5.0 - 2021-11-05
### Changed
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ subprojects {
group = 'com.github.spotbugs'
version = rootProject.version

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
}

allprojects {
Expand Down
49 changes: 37 additions & 12 deletions spotbugs/src/main/java/edu/umd/cs/findbugs/config/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import edu.umd.cs.findbugs.DetectorFactoryCollection;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import edu.umd.cs.findbugs.ba.AnalysisContext;
import edu.umd.cs.findbugs.charsets.UTF8;
Expand Down Expand Up @@ -313,18 +315,9 @@ private int parse(String argv[], boolean dryRun) throws IOException, HelpRequest
++arg;
continue;
}
String optionExtraPart = "";
int colon = option.indexOf(':');
if (colon >= 0) {
optionExtraPart = option.substring(colon + 1);
option = option.substring(0, colon);
}
int eq = option.indexOf('=');
if (eq >= 0) {
assert optionExtraPart.isEmpty();
optionExtraPart = option.substring(eq); // starts with '='
option = option.substring(0, eq);
}
Option split = splitOption(option);
option = split.option;
String optionExtraPart = split.extraPart;

if (optionDescriptionMap.get(option) == null) {
throw new IllegalArgumentException("Unknown option: " + option);
Expand All @@ -351,6 +344,38 @@ private int parse(String argv[], boolean dryRun) throws IOException, HelpRequest
return arg;
}

@NonNull
/* visible for testing */ static Option splitOption(String option) {
String optionExtraPart = "";
int colon = option.indexOf(':');
if (colon >= 0) {
optionExtraPart = option.substring(colon + 1);
option = option.substring(0, colon);
}
int eq = option.indexOf('=');
if (eq >= 0) {
if (optionExtraPart.isEmpty()) {
optionExtraPart = option.substring(eq); // starts with '='
} else {
optionExtraPart = option.substring(eq) + ":" + optionExtraPart;
}
option = option.substring(0, eq);
}
return new Option(option, optionExtraPart);
}

static final class Option {
@NonNull
final String option;
@NonNull
final String extraPart;

Option(@NonNull String option, @NonNull String extraPart) {
this.option = Objects.requireNonNull(option);
this.extraPart = Objects.requireNonNull(extraPart);
}
}

/**
* Callback method for handling an option.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package edu.umd.cs.findbugs.config;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class CommandLineTest {
@Test
public void testNoExtraPart() {
CommandLine.Option option = CommandLine.splitOption("-html");
assertThat(option.option, is("-html"));
assertThat(option.extraPart, is(""));
}

@Test
public void testSplitOptionOnLinux() {
CommandLine.Option option = CommandLine.splitOption("-html=/path/to/spotbugs.html");
assertThat(option.option, is("-html"));
assertThat(option.extraPart, is("=/path/to/spotbugs.html"));
}

@Test
public void testSplitOptionWithColonOnLinux() {
CommandLine.Option option = CommandLine.splitOption("-html:default.xsl=/path/to/spotbugs.html");
assertThat(option.option, is("-html"));
assertThat(option.extraPart, is("default.xsl=/path/to/spotbugs.html"));
}

@Test
public void testSplitOptionOnWindows() {
CommandLine.Option option = CommandLine.splitOption("-html=C:\\path\\to\\spotbugs.html");
assertThat(option.option, is("-html"));
assertThat(option.extraPart, is("=C:\\path\\to\\spotbugs.html"));
}

@Test
public void testSplitOptionWithColonOnWindows() {
CommandLine.Option option = CommandLine.splitOption("-html:default.xsl=C:\\path\\to\\spotbugs.html");
assertThat(option.option, is("-html"));
assertThat(option.extraPart, is("default.xsl=C:\\path\\to\\spotbugs.html"));
}
}
16 changes: 5 additions & 11 deletions spotbugsTestCases/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ dependencies {
}

tasks.withType(JavaCompile).configureEach {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
}
options.compilerArgs << '-Xlint:none'
options.encoding = 'UTF-8'
if (it.name == 'classesJava17') {
Expand All @@ -58,7 +61,6 @@ tasks.named('javadoc', Javadoc).configure {
}
}

def jvmVersion = JavaVersion.current()
def classesJava8 = tasks.register('classesJava8', JavaCompile) {
destinationDirectory.set(file("$buildDir/classes/java/java8"))
classpath = sourceSets.main.compileClasspath
Expand All @@ -79,16 +81,8 @@ def classesJava17 = tasks.register('classesJava17', JavaCompile) {

tasks.named('classes').configure {
dependsOn classesJava8
if (jvmVersion.isCompatibleWith(JavaVersion.VERSION_11)) {
dependsOn classesJava11
} else {
println "skip tests for Java 11 features"
}
if (jvmVersion.isCompatibleWith(JavaVersion.VERSION_17)) {
dependsOn classesJava17
} else {
println "skip tests for Java 17 features"
}
dependsOn classesJava11
dependsOn classesJava17
}

sonarqube {
Expand Down
16 changes: 8 additions & 8 deletions spotbugsTestCases/src/java/sfBugsNew/Bug1314.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import edu.umd.cs.findbugs.annotations.ExpectWarning;

public class Bug1314 {
@ExpectWarning("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
public String getFirstChildName(Element e) {
NodeList list = e.getElementsByTagName("child");
if(list != null) {
return ((Element)list.item(0)).getAttribute("name");
}
return null;
}
@ExpectWarning("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
public String getFirstChildName(Element e) {
NodeList list = e.getElementsByTagName("child");
if(list != null) {
return ((Element)list.item(0)).getAttribute("name");
}
return null;
}
}
16 changes: 8 additions & 8 deletions spotbugsTestCases/src/java/sfBugsNew/Bug1315.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import edu.umd.cs.findbugs.annotations.ExpectWarning;

public class Bug1315 {
@ExpectWarning("INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE")
public String getLastListElement(List<String> list) {
int s = list.size();
if(s >= 0) {
return list.get(s-1);
}
return null;
}
@ExpectWarning("INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE")
public String getLastListElement(List<String> list) {
int s = list.size();
if(s >= 0) {
return list.get(s-1);
}
return null;
}
}
36 changes: 18 additions & 18 deletions spotbugsTestCases/src/java/sfBugsNew/Bug1319.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@

public class Bug1319 {
@ExpectWarning("DMI_HARDCODED_ABSOLUTE_FILENAME")
public void win32PathD() {
new File("d:\\test.txt");
}

@NoWarning("DMI_HARDCODED_ABSOLUTE_FILENAME")
public void strangePath() {
new File("_:/test.txt");
}

@ExpectWarning("DMI_HARDCODED_ABSOLUTE_FILENAME")
public void win32PathDNoSlash() {
new File("d:test.txt");
}

@ExpectWarning("DMI_HARDCODED_ABSOLUTE_FILENAME")
public void win32PathUNC() {
new File("\\\\server\\share\\fileName.txt");
}
public void win32PathD() {
new File("d:\\test.txt");
}

@NoWarning("DMI_HARDCODED_ABSOLUTE_FILENAME")
public void strangePath() {
new File("_:/test.txt");
}

@ExpectWarning("DMI_HARDCODED_ABSOLUTE_FILENAME")
public void win32PathDNoSlash() {
new File("d:test.txt");
}

@ExpectWarning("DMI_HARDCODED_ABSOLUTE_FILENAME")
public void win32PathUNC() {
new File("\\\\server\\share\\fileName.txt");
}
}

0 comments on commit ff31e03

Please sign in to comment.