From ad0a0384ed4ecbc346b6a98b2a7c5060757ec00c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Fri, 19 Dec 2025 18:49:19 +0100 Subject: [PATCH] :technologist: check for common coding errors --- .github/workflows/_static-analysis.yml | 2 +- pom.xml | 11 +++++++++++ src/main/java/com/mindee/geometry/Point.java | 5 +++++ src/main/java/com/mindee/geometry/Polygon.java | 5 +++++ src/main/java/com/mindee/http/MindeeHttpApiV2.java | 8 ++++---- src/main/java/com/mindee/input/InputSourceUtils.java | 8 +++----- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/workflows/_static-analysis.yml b/.github/workflows/_static-analysis.yml index cc96ec2e8..491599990 100644 --- a/.github/workflows/_static-analysis.yml +++ b/.github/workflows/_static-analysis.yml @@ -20,4 +20,4 @@ jobs: cache: "maven" - name: Check Code Style - run: mvn --update-snapshots --no-transfer-progress spotless:check + run: mvn --update-snapshots --no-transfer-progress spotless:check pmd:check diff --git a/pom.xml b/pom.xml index 7f77f70f9..68a538883 100644 --- a/pom.xml +++ b/pom.xml @@ -94,6 +94,17 @@ 1.8 + + org.apache.maven.plugins + maven-pmd-plugin + 3.23.0 + + false + true + 3 + 1.8 + + com.diffplug.spotless spotless-maven-plugin diff --git a/src/main/java/com/mindee/geometry/Point.java b/src/main/java/com/mindee/geometry/Point.java index cbcc2bbe4..fb925d790 100644 --- a/src/main/java/com/mindee/geometry/Point.java +++ b/src/main/java/com/mindee/geometry/Point.java @@ -30,4 +30,9 @@ public boolean equals(Object object) { Point point = (Point) object; return this.x.equals(point.x) && this.y.equals(point.y); } + + @Override + public int hashCode() { + return x.hashCode() + y.hashCode(); + } } diff --git a/src/main/java/com/mindee/geometry/Polygon.java b/src/main/java/com/mindee/geometry/Polygon.java index d76a317ef..8369204b0 100644 --- a/src/main/java/com/mindee/geometry/Polygon.java +++ b/src/main/java/com/mindee/geometry/Polygon.java @@ -83,4 +83,9 @@ public boolean equals(Object object) { } return true; } + + @Override + public int hashCode() { + return coordinates.hashCode(); + } } diff --git a/src/main/java/com/mindee/http/MindeeHttpApiV2.java b/src/main/java/com/mindee/http/MindeeHttpApiV2.java index ad1c1e67e..c8a4f832d 100644 --- a/src/main/java/com/mindee/http/MindeeHttpApiV2.java +++ b/src/main/java/com/mindee/http/MindeeHttpApiV2.java @@ -73,7 +73,7 @@ public JobResponse reqPostInferenceEnqueue( InferenceParameters options ) { String url = this.mindeeSettings.getBaseUrl() + "/inferences/enqueue"; - HttpPost post = buildHttpPost(url, options); + HttpPost post = buildHttpPost(url); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.EXTENDED); @@ -101,7 +101,7 @@ public JobResponse reqPostInferenceEnqueue( InferenceParameters options ) { String url = this.mindeeSettings.getBaseUrl() + "/inferences/enqueue"; - HttpPost post = buildHttpPost(url, options); + HttpPost post = buildHttpPost(url); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.EXTENDED); @@ -112,7 +112,7 @@ public JobResponse reqPostInferenceEnqueue( /** * Executes an enqueue action, common to URL & local inputs. - * + * * @param post HTTP Post object. * @return a valid job response. */ @@ -253,7 +253,7 @@ private HttpEntity buildHttpBody(MultipartEntityBuilder builder, InferenceParame return builder.build(); } - private HttpPost buildHttpPost(String url, InferenceParameters params) { + private HttpPost buildHttpPost(String url) { HttpPost post; try { URIBuilder uriBuilder = new URIBuilder(url); diff --git a/src/main/java/com/mindee/input/InputSourceUtils.java b/src/main/java/com/mindee/input/InputSourceUtils.java index 9ebbc15a9..1c1b1eff4 100644 --- a/src/main/java/com/mindee/input/InputSourceUtils.java +++ b/src/main/java/com/mindee/input/InputSourceUtils.java @@ -71,14 +71,12 @@ public static String[] splitNameStrict(String filename) throws MindeeException { * Returns true if the file is a PDF. */ public static boolean isPdf(byte[] fileBytes) { - try ( - PDDocument document = Loader - .loadPDF(new RandomAccessReadBuffer(new ByteArrayInputStream(fileBytes))) - ) { - return true; + try { + Loader.loadPDF(new RandomAccessReadBuffer(new ByteArrayInputStream(fileBytes))); } catch (IOException e) { return false; } + return true; } /**