Skip to content

Commit 3b7436a

Browse files
authored
Fix compiler warnings
The legacy code produced a number of compiler warnings when building, which might distract from actual issues being introduced. Enable all recommended warnings when building and address all compiler warnings, mostly with a real fix, and suppress warnings in select cases where a fix is not feasible, so that the library compiles without any warnings.
2 parents dc6e323 + 9beed7e commit 3b7436a

120 files changed

Lines changed: 401 additions & 160 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ subprojects {
2323
apply plugin: 'maven-publish'
2424
apply plugin: "com.github.sherter.google-java-format"
2525

26+
compileJava {
27+
options.compilerArgs << '-Xlint:all'
28+
}
29+
30+
compileTestJava {
31+
options.compilerArgs << '-Xlint:all'
32+
}
33+
2634
repositories {
2735
mavenLocal()
2836
maven {

ocpp-common/src/main/java/eu/chargetime/ocpp/CallErrorException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
2727

2828
/** Exception returned to an outgoing request if an error is reported from the other end. */
2929
public class CallErrorException extends Exception {
30+
private static final long serialVersionUID = 2491636769263746241L;
3031

3132
private String errorCode;
3233
private String errorDescription;

ocpp-common/src/main/java/eu/chargetime/ocpp/Communicator.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
2727
SOFTWARE.
2828
*/
2929

30+
import eu.chargetime.ocpp.feature.Feature;
3031
import eu.chargetime.ocpp.model.*;
3132
import java.util.ArrayDeque;
3233
import org.slf4j.Logger;
@@ -54,6 +55,7 @@ public abstract class Communicator {
5455
* @param payload the raw formatted payload.
5556
* @param type the expected return type.
5657
* @return the unpacked payload.
58+
* @param <T> the type of the unpacked payload.
5759
* @throws Exception error occurred while converting.
5860
*/
5961
public abstract <T> T unpackPayload(Object payload, Class<T> type) throws Exception;
@@ -70,7 +72,7 @@ public abstract class Communicator {
7072
* Create a call result envelope to transmit.
7173
*
7274
* @param uniqueId the id the receiver expects.
73-
* @param action action name of the feature.
75+
* @param action action name of the {@link Feature}.
7476
* @param payload packed payload.
7577
* @return a fully packed message ready to send.
7678
*/
@@ -80,7 +82,7 @@ public abstract class Communicator {
8082
* Create a call envelope to transmit to the server.
8183
*
8284
* @param uniqueId the id the receiver must reply with.
83-
* @param action action name of the feature.
85+
* @param action action name of the {@link Feature}.
8486
* @param payload packed payload.
8587
* @return a fully packed message ready to send.
8688
*/
@@ -90,6 +92,7 @@ public abstract class Communicator {
9092
* Create a call error envelope to transmit.
9193
*
9294
* @param uniqueId the id the receiver expects.
95+
* @param action action name of the {@link Feature}.
9396
* @param errorCode an OCPP error code.
9497
* @param errorDescription an associated error description.
9598
* @return a fully packed message ready to send.
@@ -101,6 +104,7 @@ protected abstract Object makeCallError(
101104
* Create a call result error envelope to transmit.
102105
*
103106
* @param uniqueId the id the receiver expects.
107+
* @param action action name of the {@link Feature}.
104108
* @param errorCode an OCPP error code.
105109
* @param errorDescription an associated error description.
106110
* @return a fully packed message ready to send.
@@ -112,7 +116,7 @@ protected abstract Object makeCallResultError(
112116
* Create a send envelope to transmit to the server.
113117
*
114118
* @param uniqueId the id of the message.
115-
* @param action action name of the feature.
119+
* @param action action name of the {@link Feature}.
116120
* @param payload packed payload.
117121
* @return a fully packed message ready to send.
118122
*/
@@ -177,7 +181,7 @@ public void accept(CommunicatorEvents events) {
177181
* Request}s.
178182
*
179183
* @param uniqueId the id the receiver should use to reply.
180-
* @param action action name of the {@link eu.chargetime.ocpp.feature.Feature}.
184+
* @param action action name of the {@link Feature}.
181185
* @param request the outgoing {@link Request}
182186
*/
183187
public synchronized void sendCall(String uniqueId, String action, Request request) {
@@ -222,6 +226,7 @@ public synchronized void sendCall(String uniqueId, String action, Request reques
222226
* Send a {@link Confirmation} reply to a {@link Request}.
223227
*
224228
* @param uniqueId the id the receiver expects.
229+
* @param action action name of the {@link Feature}.
225230
* @param confirmation the outgoing {@link Confirmation}
226231
*/
227232
public void sendCallResult(String uniqueId, String action, Confirmation confirmation) {
@@ -255,7 +260,8 @@ public void sendCallResult(String uniqueId, String action, Confirmation confirma
255260
* Send an error. If offline, the message is thrown away.
256261
*
257262
* @param uniqueId the id the receiver expects a response to.
258-
* @param errorCode an OCPP error Code
263+
* @param action action name of the {@link Feature}.
264+
* @param errorCode an OCPP error Code.
259265
* @param errorDescription a associated error description.
260266
*/
261267
public void sendCallError(
@@ -282,7 +288,8 @@ public void sendCallError(
282288
* Send a call result error. If offline, the message is thrown away.
283289
*
284290
* @param uniqueId the id the receiver expects a response to.
285-
* @param errorCode an OCPP error Code
291+
* @param action action name of the {@link Feature}.
292+
* @param errorCode an OCPP error Code.
286293
* @param errorDescription a associated error description.
287294
*/
288295
public void sendCallResultError(
@@ -310,7 +317,7 @@ public void sendCallResultError(
310317
* Send a {@link Request} which has no confirmation.
311318
*
312319
* @param uniqueId the id of the {@link Request}.
313-
* @param action action name of the {@link eu.chargetime.ocpp.feature.Feature}.
320+
* @param action action name of the {@link Feature}.
314321
* @param request the outgoing {@link Request}
315322
*/
316323
public synchronized void send(String uniqueId, String action, Request request) {

ocpp-common/src/main/java/eu/chargetime/ocpp/NotConnectedException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ of this software and associated documentation files (the "Software"), to deal
2424
SOFTWARE.
2525
*/
2626

27-
public class NotConnectedException extends Exception {}
27+
public class NotConnectedException extends Exception {
28+
private static final long serialVersionUID = -2192470845608175121L;
29+
}

ocpp-common/src/main/java/eu/chargetime/ocpp/OccurenceConstraintException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ of this software and associated documentation files (the "Software"), to deal
2525
*/
2626

2727
/** Exception thrown when trying to send a request that isn't valid. */
28-
public class OccurenceConstraintException extends Exception {}
28+
public class OccurenceConstraintException extends Exception {
29+
private static final long serialVersionUID = -8870111792165582976L;
30+
}

ocpp-common/src/main/java/eu/chargetime/ocpp/PropertyConstraintException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
2828

2929
/** Exception used when validating fields. */
3030
public class PropertyConstraintException extends IllegalArgumentException {
31-
31+
private static final long serialVersionUID = 7561578774874709893L;
3232
private static final String EXCEPTION_MESSAGE_TEMPLATE =
3333
"Validation failed: [%s]. Current Value: [%s]";
3434

ocpp-common/src/main/java/eu/chargetime/ocpp/SecurityErrorException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ of this software and associated documentation files (the "Software"), to deal
2929

3030
/** A security issue occurred */
3131
public class SecurityErrorException extends IllegalStateException {
32+
private static final long serialVersionUID = 630599636179474207L;
33+
3234
public SecurityErrorException(String s) {
3335
super(s);
3436
}

ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ public void close() {
227227
* @throws UnsupportedFeatureException Thrown if the feature isn't among the list of supported
228228
* features.
229229
* @throws OccurenceConstraintException Thrown if the request isn't valid.
230+
* @throws NotConnectedException Thrown if session with passed sessionIndex is not found
230231
*/
231232
public CompletableFuture<Confirmation> send(UUID sessionIndex, Request request)
232233
throws UnsupportedFeatureException, OccurenceConstraintException, NotConnectedException {
@@ -275,6 +276,9 @@ public CompletableFuture<Confirmation> send(UUID sessionIndex, Request request)
275276
* @param confirmation the {@link Confirmation} to the original {@link Request}.
276277
* @return a boolean indicating if pending request was found.
277278
* @throws NotConnectedException Thrown if session with passed sessionIndex is not found
279+
* @throws UnsupportedFeatureException Thrown if the feature isn't among the list of supported
280+
* features.
281+
* @throws OccurenceConstraintException Thrown if the request isn't valid.
278282
*/
279283
public boolean asyncCompleteRequest(UUID sessionIndex, String uniqueId, Confirmation confirmation)
280284
throws NotConnectedException, UnsupportedFeatureException, OccurenceConstraintException {

ocpp-common/src/main/java/eu/chargetime/ocpp/Session.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public class Session implements ISession {
6464
*
6565
* @param communicator send and receive messages.
6666
* @param queue store and restore requests based on unique ids.
67+
* @param fulfiller the {@link PromiseFulfiller} to use
68+
* @param featureRepository the {@link IFeatureRepository} to use
6769
*/
6870
public Session(
6971
Communicator communicator,
@@ -150,6 +152,7 @@ public void removeRequest(String ticket) {
150152
* Send a {@link Confirmation} to a {@link Request}
151153
*
152154
* @param uniqueId the unique identification the receiver expects.
155+
* @param action action name to identify the feature.
153156
* @param confirmation the {@link Confirmation} payload to send.
154157
*/
155158
public void sendConfirmation(String uniqueId, String action, Confirmation confirmation) {

ocpp-common/src/main/java/eu/chargetime/ocpp/SessionEvents.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public interface SessionEvents {
4747
*
4848
* @param request the {@link Request}.
4949
* @return a {@link Confirmation} to send as a response or {@code null} if none to send.
50+
* @throws UnsupportedFeatureException Thrown if the feature isn't among the list of supported
51+
* features.
5052
*/
5153
@Nullable
5254
Confirmation handleRequest(Request request) throws UnsupportedFeatureException;
@@ -57,6 +59,9 @@ public interface SessionEvents {
5759
* @param uniqueId the unique id used for the {@link Request}.
5860
* @param confirmation the {@link Confirmation} to the {@link Request}.
5961
* @return a boolean indicating if pending request was found.
62+
* @throws UnsupportedFeatureException Thrown if the feature isn't among the list of supported
63+
* features.
64+
* @throws OccurenceConstraintException Thrown if the request isn't valid.
6065
*/
6166
boolean asyncCompleteRequest(String uniqueId, Confirmation confirmation)
6267
throws UnsupportedFeatureException, OccurenceConstraintException;

0 commit comments

Comments
 (0)