Skip to content

Commit d87b6e8

Browse files
authored
🧑‍💻 check for common coding errors (#291)
1 parent 7089b75 commit d87b6e8

6 files changed

Lines changed: 29 additions & 10 deletions

File tree

.github/workflows/_static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
cache: "maven"
2121

2222
- name: Check Code Style
23-
run: mvn --update-snapshots --no-transfer-progress spotless:check
23+
run: mvn --update-snapshots --no-transfer-progress spotless:check pmd:check

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@
9494
<target>1.8</target>
9595
</configuration>
9696
</plugin>
97+
<plugin>
98+
<groupId>org.apache.maven.plugins</groupId>
99+
<artifactId>maven-pmd-plugin</artifactId>
100+
<version>3.23.0</version>
101+
<configuration>
102+
<linkXRef>false</linkXRef>
103+
<printFailingErrors>true</printFailingErrors>
104+
<failurePriority>3</failurePriority>
105+
<targetJdk>1.8</targetJdk>
106+
</configuration>
107+
</plugin>
97108
<plugin>
98109
<groupId>com.diffplug.spotless</groupId>
99110
<artifactId>spotless-maven-plugin</artifactId>

src/main/java/com/mindee/geometry/Point.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ public boolean equals(Object object) {
3030
Point point = (Point) object;
3131
return this.x.equals(point.x) && this.y.equals(point.y);
3232
}
33+
34+
@Override
35+
public int hashCode() {
36+
return x.hashCode() + y.hashCode();
37+
}
3338
}

src/main/java/com/mindee/geometry/Polygon.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,9 @@ public boolean equals(Object object) {
8383
}
8484
return true;
8585
}
86+
87+
@Override
88+
public int hashCode() {
89+
return coordinates.hashCode();
90+
}
8691
}

src/main/java/com/mindee/http/MindeeHttpApiV2.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public JobResponse reqPostInferenceEnqueue(
7373
InferenceParameters options
7474
) {
7575
String url = this.mindeeSettings.getBaseUrl() + "/inferences/enqueue";
76-
HttpPost post = buildHttpPost(url, options);
76+
HttpPost post = buildHttpPost(url);
7777

7878
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
7979
builder.setMode(HttpMultipartMode.EXTENDED);
@@ -101,7 +101,7 @@ public JobResponse reqPostInferenceEnqueue(
101101
InferenceParameters options
102102
) {
103103
String url = this.mindeeSettings.getBaseUrl() + "/inferences/enqueue";
104-
HttpPost post = buildHttpPost(url, options);
104+
HttpPost post = buildHttpPost(url);
105105

106106
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
107107
builder.setMode(HttpMultipartMode.EXTENDED);
@@ -112,7 +112,7 @@ public JobResponse reqPostInferenceEnqueue(
112112

113113
/**
114114
* Executes an enqueue action, common to URL & local inputs.
115-
*
115+
*
116116
* @param post HTTP Post object.
117117
* @return a valid job response.
118118
*/
@@ -253,7 +253,7 @@ private HttpEntity buildHttpBody(MultipartEntityBuilder builder, InferenceParame
253253
return builder.build();
254254
}
255255

256-
private HttpPost buildHttpPost(String url, InferenceParameters params) {
256+
private HttpPost buildHttpPost(String url) {
257257
HttpPost post;
258258
try {
259259
URIBuilder uriBuilder = new URIBuilder(url);

src/main/java/com/mindee/input/InputSourceUtils.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,12 @@ public static String[] splitNameStrict(String filename) throws MindeeException {
7171
* Returns true if the file is a PDF.
7272
*/
7373
public static boolean isPdf(byte[] fileBytes) {
74-
try (
75-
PDDocument document = Loader
76-
.loadPDF(new RandomAccessReadBuffer(new ByteArrayInputStream(fileBytes)))
77-
) {
78-
return true;
74+
try {
75+
Loader.loadPDF(new RandomAccessReadBuffer(new ByteArrayInputStream(fileBytes)));
7976
} catch (IOException e) {
8077
return false;
8178
}
79+
return true;
8280
}
8381

8482
/**

0 commit comments

Comments
 (0)