Skip to content

Commit 6b59646

Browse files
committed
JNI/JSSE: Code cleanup from SpotBugs review
- Make 14 inner classes static where outer instance is not needed - Remove unnecessary transient on lock fields in WolfSSLCRL and WolfSSLCertificate - Remove dead local variables in WolfSSLDebug log() and JSONFormatter
1 parent fc867c3 commit 6b59646

6 files changed

Lines changed: 15 additions & 30 deletions

File tree

src/java/com/wolfssl/WolfSSLDebug.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,6 @@ public String format(LogRecord record) {
239239
return "{\"error\": \"null record\"}\n";
240240
}
241241

242-
String sourceClass = record.getSourceClassName();
243-
if (sourceClass == null) {
244-
sourceClass = "unknown";
245-
} else {
246-
/* Extract simple class name (after last dot) */
247-
int lastDot = sourceClass.lastIndexOf('.');
248-
if (lastDot >= 0) {
249-
sourceClass = sourceClass.substring(lastDot + 1);
250-
}
251-
}
252-
253242
String component;
254243
String loggerName = record.getLoggerName();
255244
if (loggerName != null && loggerName.contains("jni")) {
@@ -452,11 +441,6 @@ public static synchronized <T> void log(Class<T> cl, Component component,
452441

453442
Level level = tag.equals(ERROR) ? Level.SEVERE : Level.INFO;
454443

455-
String className = cl.getSimpleName();
456-
if (nativePtr != 0) {
457-
className = className + ": " + nativePtr;
458-
}
459-
460444
LogRecord record = new LogRecord(level, messageSupplier.get());
461445
record.setSourceClassName(cl.getName());
462446
record.setLoggerName(targetLogger.getName());

src/java/com/wolfssl/provider/jsse/WolfSSLAuthStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ protected void updateTimeouts(int in, int side) {
790790
}
791791
}
792792

793-
private class SessionStore<K, V> extends LinkedHashMap<K, V> {
793+
private static class SessionStore<K, V> extends LinkedHashMap<K, V> {
794794
/**
795795
* user defined ID
796796
*/

src/java/com/wolfssl/provider/jsse/WolfSSLEngine.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,7 +2703,7 @@ protected synchronized int internalSessionTicketCb(byte[] ticket) {
27032703
return 0;
27042704
}
27052705

2706-
private class SendCB implements WolfSSLByteBufferIOSendCallback {
2706+
private static class SendCB implements WolfSSLByteBufferIOSendCallback {
27072707

27082708
protected SendCB() {
27092709

@@ -2716,7 +2716,7 @@ public int sendCallback(WolfSSLSession ssl, ByteBuffer toSend, int sz,
27162716

27172717
}
27182718

2719-
private class RecvCB implements WolfSSLByteBufferIORecvCallback {
2719+
private static class RecvCB implements WolfSSLByteBufferIORecvCallback {
27202720

27212721
protected RecvCB() {
27222722

@@ -2729,7 +2729,8 @@ public int receiveCallback(WolfSSLSession ssl, ByteBuffer buf, int sz,
27292729

27302730
}
27312731

2732-
private class SessionTicketCB implements WolfSSLSessionTicketCallback {
2732+
private static class SessionTicketCB
2733+
implements WolfSSLSessionTicketCallback {
27332734

27342735
protected SessionTicketCB() {
27352736
}

src/java/com/wolfssl/provider/jsse/WolfSSLProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public final class WolfSSLProvider extends Provider {
4242
/**
4343
* Inner callback class for wolfCrypt FIPS 140-2/3 errors
4444
*/
45-
public class JSSEFIPSErrorCallback implements WolfSSLFIPSErrorCallback {
45+
public static class JSSEFIPSErrorCallback implements WolfSSLFIPSErrorCallback {
4646

4747
/** Default JSSEFIPSErrorCallback constructor */
4848
public JSSEFIPSErrorCallback() { }

src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ protected synchronized void finalize() throws Throwable {
23442344
* wolfSSL send callback context, used with SocketSendCallback to
23452345
* gain access to the underlying Socket object.
23462346
*/
2347-
class SocketSendCtx {
2347+
static class SocketSendCtx {
23482348
private Socket sock = null;
23492349

23502350
public SocketSendCtx(Socket s) {
@@ -2360,7 +2360,7 @@ public Socket getSocket() {
23602360
* wolfSSL receive callback context, used with SocketRecvCallback to
23612361
* gain access to the underlying Socket object.
23622362
*/
2363-
class SocketRecvCtx {
2363+
static class SocketRecvCtx {
23642364
private Socket sock = null;
23652365

23662366
public SocketRecvCtx(Socket s) {
@@ -2381,7 +2381,7 @@ public Socket getSocket() {
23812381
* subclasses contain an internal file descriptor (fd), or alternatively
23822382
* expect the calling application to do I/O using the InputStream and
23832383
* OutputStream of the Socket */
2384-
class SocketSendCallback implements WolfSSLIOSendCallback {
2384+
static class SocketSendCallback implements WolfSSLIOSendCallback {
23852385

23862386
/**
23872387
* I/O send callback method.
@@ -2439,7 +2439,7 @@ public int sendCallback(WolfSSLSession ssl,
24392439
* subclasses contain an internal file descriptor (fd), or alternatively
24402440
* expect the calling application to do I/O using the InputStream and
24412441
* OutputStream of the Socket */
2442-
class SocketRecvCallback implements WolfSSLIORecvCallback {
2442+
static class SocketRecvCallback implements WolfSSLIORecvCallback {
24432443

24442444
/**
24452445
* I/O receive callback method.
@@ -2500,7 +2500,7 @@ public int receiveCallback(WolfSSLSession ssl,
25002500
* wolfSSL receive callback context, used with ConsumedRecvCallback to
25012501
* gain access to underlying Socket and InputStream objects.
25022502
*/
2503-
class ConsumedRecvCtx {
2503+
static class ConsumedRecvCtx {
25042504
private Socket s = null;
25052505
private DataInputStream consumed = null;
25062506
private DataInputStream sockStream = null;
@@ -2547,7 +2547,7 @@ public synchronized void closeDataStreams()
25472547
* This callback will read all data from the pre-existing/populated
25482548
* InputStream first, then start reading from the Socket proper.
25492549
*/
2550-
class ConsumedRecvCallback implements WolfSSLIORecvCallback {
2550+
static class ConsumedRecvCallback implements WolfSSLIORecvCallback {
25512551

25522552
public int receiveCallback(WolfSSLSession ssl, byte[] buf,
25532553
int sz, Object ctx) {
@@ -2592,7 +2592,7 @@ public int receiveCallback(WolfSSLSession ssl, byte[] buf,
25922592
}
25932593
}
25942594

2595-
class WolfSSLInputStream extends InputStream {
2595+
static class WolfSSLInputStream extends InputStream {
25962596

25972597
private WolfSSLSession ssl;
25982598
private WolfSSLSocket socket;
@@ -2834,7 +2834,7 @@ public synchronized int read(byte[] b, int off, int len)
28342834
}
28352835
} /* end WolfSSLInputStream inner class */
28362836

2837-
class WolfSSLOutputStream extends OutputStream {
2837+
static class WolfSSLOutputStream extends OutputStream {
28382838

28392839
private WolfSSLSession ssl;
28402840
private WolfSSLSocket socket;

src/java/com/wolfssl/provider/jsse/WolfSSLX509.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ protected void finalize() throws Throwable {
689689
}
690690

691691
/* wolfSSL Principal class */
692-
private class WolfSSLPrincipal implements Principal {
692+
private static class WolfSSLPrincipal implements Principal {
693693
private String name;
694694
private String[] DNs = { "/emailAddress=", "/CN=", "/OU=",
695695
"/O=", "/L=", "/ST=", "/C="};

0 commit comments

Comments
 (0)