Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Add another spotbugs plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mfvanek committed Dec 23, 2023
1 parent 64bcda0 commit 3faf8a4
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 14 deletions.
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ dependencies {

//pitest("it.mulders.stryker:pit-dashboard-reporter:0.2.1")
checkstyle("com.thomasjensen.checkstyle.addons:checkstyle-addons:7.0.1")

errorprone("com.google.errorprone:error_prone_core:2.24.0")
errorprone("jp.skypencil.errorprone.slf4j:errorprone-slf4j:0.1.21")

spotbugsPlugins("jp.skypencil.findbugs.slf4j:bug-pattern:1.5.0")
spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0")
spotbugsPlugins("com.mebigfatguy.sb-contrib:sb-contrib:7.6.4")
}

application {
Expand All @@ -62,6 +68,7 @@ tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.add("-parameters")
options.errorprone {
disableWarningsInGeneratedCode.set(true)
disable("Slf4jLoggerShouldBeNonStatic")
}
}

Expand Down
28 changes: 26 additions & 2 deletions config/spotbugs/exclude.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2,CT_CONSTRUCTOR_THROW"/>
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2,CT_CONSTRUCTOR_THROW,SLF4J_LOGGER_SHOULD_BE_NON_STATIC,LO_INVALID_STRING_FORMAT_NOTATION"/>
</Match>
<Match>
<Bug pattern="NP_NULL_PARAM_DEREF_NONVIRTUAL"/>
<Bug pattern="CLI_CONSTANT_LIST_INDEX,EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS,EXS_EXCEPTION_SOFTENING_NO_CHECKED,WEM_WEAK_EXCEPTION_MESSAGING,OPM_OVERLY_PERMISSIVE_METHOD,STT_TOSTRING_STORED_IN_FIELD,STT_STRING_PARSING_A_FIELD"/>
</Match>
<Match>
<Bug pattern="IMC_IMMATURE_CLASS_NO_TOSTRING"/>
<Or>
<Class name="io.github.mfvanek.image.resizing.resizers.ResizersFactory"/>
<Class name="io.github.mfvanek.image.resizing.utils.ParamsValidator"/>
</Or>
</Match>
<Match>
<Bug pattern="USBR_UNNECESSARY_STORE_BEFORE_RETURN"/>
<Class name="io.github.mfvanek.image.resizing.pojos.ImageDimension"/>
</Match>
<Match>
<Bug pattern="NP_NULL_PARAM_DEREF_NONVIRTUAL,SEC_SIDE_EFFECT_CONSTRUCTOR"/>
<Class name="~.*Test"/>
</Match>
<Match>
<Bug pattern="CRLF_INJECTION_LOGS,WEAK_FILENAMEUTILS"/>
</Match>
<Match>
<Bug pattern="PATH_TRAVERSAL_IN"/>
<Or>
<Class name="io.github.mfvanek.image.resizing.DemoApp"/>
<Class name="io.github.mfvanek.image.resizing.resizers.AwtGraphicsProvider"/>
</Or>
</Match>
</FindBugsFilter>
9 changes: 5 additions & 4 deletions src/main/java/io/github/mfvanek/image/resizing/DemoApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ public static void main(final String[] args) {
final ResizeParams resizeParams = ParamsValidator.builder(args).useDefaultIfNeed().withAlgorithm(ResizeType.RAW).validate();
process(graphicsProvider, resizeParams);
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
log.error("Error occurred while creating temp folder", e);

Check warning on line 55 in src/main/java/io/github/mfvanek/image/resizing/DemoApp.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/mfvanek/image/resizing/DemoApp.java#L55

Added line #L55 was not covered by tests
}
}

private static void process(final GraphicsProvider graphicsProvider, final ResizeParams resizeParams) {
try {
if (graphicsProvider.isFormatNotSupported(resizeParams.getExtension())) {
log.warn("File format '{}' is not supported", resizeParams.getExtension());
final String extension = resizeParams.getExtension();

Check warning on line 61 in src/main/java/io/github/mfvanek/image/resizing/DemoApp.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/mfvanek/image/resizing/DemoApp.java#L61

Added line #L61 was not covered by tests
if (graphicsProvider.isFormatNotSupported(extension)) {
log.warn("File format '{}' is not supported", extension);

Check warning on line 63 in src/main/java/io/github/mfvanek/image/resizing/DemoApp.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/mfvanek/image/resizing/DemoApp.java#L63

Added line #L63 was not covered by tests
return;
}

Expand All @@ -75,7 +76,7 @@ private static void process(final GraphicsProvider graphicsProvider, final Resiz
log.error("Unable to load given image");
}
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
log.error("Error occurred while saving resized image", e);

Check warning on line 79 in src/main/java/io/github/mfvanek/image/resizing/DemoApp.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/mfvanek/image/resizing/DemoApp.java#L79

Added line #L79 was not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ResizeParams implements ImageParams {
private final Dimensional dimensional;
private final ResizeType algorithm;
private final boolean convertToGrayscale;
private final boolean similarToURL;

protected ResizeParams(final String pathToFile,
final Dimensional dimensional,
Expand All @@ -42,6 +43,7 @@ protected ResizeParams(final String pathToFile,
this.dimensional = dimensional;
this.algorithm = algorithm;
this.convertToGrayscale = convertToGrayscale;
this.similarToURL = this.pathToFileLowercased.startsWith("http");
}

public static ResizeParams newWithAlgorithm(final String pathToFile,
Expand All @@ -68,7 +70,7 @@ public String getPathToFile() {

@Override
public boolean isSimilarToURL() {
return pathToFileLowercased.startsWith("http");
return similarToURL;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public BufferedImage loadImage(final URI uri) {
final File file = new File(uri);
return ImageIO.read(file);
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
throw new RuntimeException(e);
}
}
Expand All @@ -50,7 +49,6 @@ public BufferedImage loadImage(final URL url) {
try {
return ImageIO.read(url);
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ private static int toDimensionValue(final String value, final String paramName)
try {
return Integer.parseInt(value, 10);
} catch (NumberFormatException e) {
log.error(e.getLocalizedMessage(), e);
throw new IllegalArgumentException(String.format("The %s has an invalid format or value", paramName), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ void createGraphicsProvider() {

@Test
void correctness() {
final Set<Class<?>> resizers = new HashSet<>();
for (final ResizeType resizeType : ResizeType.values()) {
final ResizeType[] types = ResizeType.values();
final Set<Class<?>> resizers = new HashSet<>(types.length);
for (final ResizeType resizeType : types) {
resizers.add(ResizersFactory.getByAlgorithm(resizeType).getClass());
}
assertThat(resizers)
.hasSameSizeAs(ResizeType.values());
.hasSameSizeAs(types);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void withCorrectArgs() {
assertThat(ParamsValidator.builder("file:/any-picture.BMP", "111", "222").validate())
.isNotNull()
.hasToString("ResizeParams(pathToFile=file:/any-picture.BMP, pathToFileLowercased=file:/any-picture.bmp, " +
"dimensional=ImageDimension(width=111, height=222), algorithm=RAW, convertToGrayscale=true)")
"dimensional=ImageDimension(width=111, height=222), algorithm=RAW, convertToGrayscale=true, similarToURL=false)")
.satisfies(r -> {
assertThat(r.getPathToFile()).endsWith("any-picture.BMP");
assertThat(r.getWidth()).isEqualTo(111);
Expand Down

0 comments on commit 3faf8a4

Please sign in to comment.