Skip to content

Commit f913055

Browse files
committed
Fixed errors found in review
1 parent 249f669 commit f913055

File tree

6 files changed

+39
-40
lines changed

6 files changed

+39
-40
lines changed

src/main/java/org/java_websocket/AbstractWebSocket.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void setConnectionLostTimeout( int connectionLostTimeout ) {
119119
}
120120
}
121121
} catch (Exception e) {
122-
log.error("Exception during connection lost restart: " + e.getMessage());
122+
log.error("Exception during connection lost restart: {}", e);
123123
}
124124
restartConnectionLostTimer();
125125
}
@@ -174,13 +174,13 @@ public void run() {
174174
if( conn instanceof WebSocketImpl ) {
175175
webSocketImpl = ( WebSocketImpl ) conn;
176176
if( webSocketImpl.getLastPong() < current ) {
177-
log.warn("Closing connection due to no pong received: " + conn.toString());
177+
log.warn("Closing connection due to no pong received: {}", conn);
178178
webSocketImpl.closeConnection( CloseFrame.ABNORMAL_CLOSE, "The connection was closed because the other endpoint did not respond with a pong in time. For more information check: https://github.com/TooTallNate/Java-WebSocket/wiki/Lost-connection-detection" );
179179
} else {
180180
if( webSocketImpl.isOpen() ) {
181181
webSocketImpl.sendPing();
182182
} else {
183-
log.warn("Trying to ping a non open connection: " + conn.toString());
183+
log.warn("Trying to ping a non open connection: {}", conn);
184184
}
185185
}
186186
}

src/main/java/org/java_websocket/SSLSocketChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public SSLSocketChannel( SocketChannel inputSocketChannel, SSLEngine inputEngine
138138
try {
139139
socketChannel.close();
140140
} catch ( IOException e ) {
141-
log.error("Exception during the closing of the channel", e);
141+
log.error("Exception during the closing of the channel: {}", e);
142142
}
143143
}
144144
}
@@ -166,7 +166,7 @@ public synchronized int read( ByteBuffer dst ) throws IOException {
166166
try {
167167
result = engine.unwrap( peerNetData, peerAppData );
168168
} catch ( SSLException e ) {
169-
log.error("SSLExcpetion during unwrap", e);
169+
log.error("SSLExcpetion during unwrap: {}", e);
170170
throw e;
171171
}
172172
switch(result.getStatus()) {

src/main/java/org/java_websocket/SSLSocketChannel2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,12 @@ protected void createBuffers( SSLSession session ) {
232232
if( inCrypt.capacity() != netBufferMax )
233233
inCrypt = ByteBuffer.allocate( netBufferMax );
234234
}
235-
if (inData.remaining() != 0) {
235+
if (inData.remaining() != 0 && log.isTraceEnabled()) {
236236
log.trace(new String( inData.array(), inData.position(), inData.remaining()));
237237
}
238238
inData.rewind();
239239
inData.flip();
240-
if (inCrypt.remaining() != 0) {
240+
if (inCrypt.remaining() != 0 && log.isTraceEnabled()) {
241241
log.trace(new String( inCrypt.array(), inCrypt.position(), inCrypt.remaining()));
242242
}
243243
inCrypt.rewind();

src/main/java/org/java_websocket/WebSocketImpl.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
263263
try {
264264
response = wsl.onWebsocketHandshakeReceivedAsServer( this, d, handshake );
265265
} catch ( InvalidDataException e ) {
266-
log.trace("Closing due to wrong handshake. Possible handshake rejection: ", e);
266+
log.trace("Closing due to wrong handshake. Possible handshake rejection: {}", e);
267267
closeConnectionDueToWrongHandshake( e );
268268
return false;
269269
} catch ( RuntimeException e ) {
270-
log.error("Closing due to internal server error", e);
270+
log.error("Closing due to internal server error; {}", e);
271271
wsl.onWebsocketError( this, e );
272272
closeConnectionDueToInternalServerError( e );
273273
return false;
@@ -320,11 +320,11 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
320320
try {
321321
wsl.onWebsocketHandshakeReceivedAsClient( this, handshakerequest, handshake );
322322
} catch ( InvalidDataException e ) {
323-
log.trace("Closing due to invalid data exception. Possible handshake rejection: ", e);
323+
log.trace("Closing due to invalid data exception. Possible handshake rejection: {}", e);
324324
flushAndClose( e.getCloseCode(), e.getMessage(), false );
325325
return false;
326326
} catch ( RuntimeException e ) {
327-
log.error("Closing since client was never connected", e);
327+
log.error("Closing since client was never connected: {}", e);
328328
wsl.onWebsocketError( this, e );
329329
flushAndClose( CloseFrame.NEVER_CONNECTED, e.getMessage(), false );
330330
return false;
@@ -337,7 +337,7 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
337337
}
338338
}
339339
} catch ( InvalidHandshakeException e ) {
340-
log.trace("Closing due to invalid handshake", e);
340+
log.trace("Closing due to invalid handshake: {}", e);
341341
close( e );
342342
}
343343
} catch ( IncompleteHandshakeException e ) {
@@ -370,7 +370,7 @@ private void decodeFrames( ByteBuffer socketBuffer ) {
370370
draft.processFrame( this, f );
371371
}
372372
} catch ( InvalidDataException e ) {
373-
log.error("Closing due to invalid data in frame", e);
373+
log.error("Closing due to invalid data in frame: {}", e);
374374
wsl.onWebsocketError( this, e );
375375
close(e);
376376
}
@@ -441,7 +441,7 @@ public synchronized void close( int code, String message, boolean remote ) {
441441
sendFrame( closeFrame );
442442
}
443443
} catch ( InvalidDataException e ) {
444-
log.error("generated frame is invalid", e);
444+
log.error("generated frame is invalid: {}", e);
445445
wsl.onWebsocketError( this, e );
446446
flushAndClose( CloseFrame.ABNORMAL_CLOSE, "generated frame is invalid", false );
447447
}
@@ -496,9 +496,9 @@ public synchronized void closeConnection( int code, String message, boolean remo
496496
channel.close();
497497
} catch ( IOException e ) {
498498
if( e.getMessage().equals( "Broken pipe" ) ) {
499-
log.warn( "Caught IOException: Broken pipe during closeConnection()", e );
499+
log.warn( "Caught IOException: Broken pipe during closeConnection(): {}", e );
500500
} else {
501-
log.error("Exception during channel.close()", e);
501+
log.error("Exception during channel.close(); {}", e);
502502
wsl.onWebsocketError( this, e );
503503
}
504504
}
@@ -544,7 +544,7 @@ public synchronized void flushAndClose( int code, String message, boolean remote
544544
try {
545545
wsl.onWebsocketClosing( this, code, message, remote );
546546
} catch ( RuntimeException e ) {
547-
log.error("Exception in onWebsocketClosing", e);
547+
log.error("Exception in onWebsocketClosing: {}", e);
548548
wsl.onWebsocketError( this, e );
549549
}
550550
if( draft != null )
@@ -617,7 +617,7 @@ private void send( Collection<Framedata> frames ) {
617617
}
618618
ArrayList<ByteBuffer> outgoingFrames = new ArrayList<ByteBuffer>();
619619
for( Framedata f : frames ) {
620-
log.trace( "send frame: " + f );
620+
log.trace( "send frame: {}", f);
621621
outgoingFrames.add( draft.createBinaryFrame( f ) );
622622
}
623623
write( outgoingFrames );
@@ -664,17 +664,17 @@ public void startHandshake( ClientHandshakeBuilder handshakedata ) throws Invali
664664
// Stop if the client code throws an exception
665665
throw new InvalidHandshakeException( "Handshake data rejected by client." );
666666
} catch ( RuntimeException e ) {
667-
log.error("Exception in startHandshake", e);
667+
log.error("Exception in startHandshake: {}", e);
668668
wsl.onWebsocketError( this, e );
669-
throw new InvalidHandshakeException( "rejected because of" + e );
669+
throw new InvalidHandshakeException( "rejected because of " + e );
670670
}
671671

672672
// Send
673673
write( draft.createHandshake( this.handshakerequest, role ) );
674674
}
675675

676676
private void write( ByteBuffer buf ) {
677-
log.trace( "write(" + buf.remaining() + "): {" + ( buf.remaining() > 1000 ? "too big to display" : new String( buf.array() ) ) + '}' );
677+
log.trace( "write({}): {}", buf.remaining(), buf.remaining() > 1000 ? "too big to display" : new String( buf.array() ));
678678

679679
outQueue.add( buf );
680680
wsl.onWriteDemand( this );
@@ -694,7 +694,7 @@ private void write( List<ByteBuffer> bufs ) {
694694
}
695695

696696
private void open( Handshakedata d ) {
697-
log.trace( "open using draft: " + draft );
697+
log.trace( "open using draft: {}",draft );
698698
setReadyState( ReadyState.OPEN );
699699
try {
700700
wsl.onWebsocketOpen( this, d );

src/main/java/org/java_websocket/drafts/Draft_6455.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public HandshakeState acceptHandshakeAsServer( ClientHandshake handshakedata ) t
168168
if( knownExtension.acceptProvidedExtensionAsServer( requestedExtension ) ) {
169169
extension = knownExtension;
170170
extensionState = HandshakeState.MATCHED;
171-
log.trace("acceptHandshakeAsServer - Matching extension found: " + extension.toString());
171+
log.trace("acceptHandshakeAsServer - Matching extension found: {}", extension);
172172
break;
173173
}
174174
}
@@ -178,7 +178,7 @@ public HandshakeState acceptHandshakeAsServer( ClientHandshake handshakedata ) t
178178
if( knownProtocol.acceptProvidedProtocol( requestedProtocol ) ) {
179179
protocol = knownProtocol;
180180
protocolState = HandshakeState.MATCHED;
181-
log.trace("acceptHandshakeAsServer - Matching protocol found: " + protocol.toString());
181+
log.trace("acceptHandshakeAsServer - Matching protocol found: {}", protocol);
182182
break;
183183
}
184184
}
@@ -215,7 +215,7 @@ public HandshakeState acceptHandshakeAsClient( ClientHandshake request, ServerHa
215215
if( knownExtension.acceptProvidedExtensionAsClient( requestedExtension ) ) {
216216
extension = knownExtension;
217217
extensionState = HandshakeState.MATCHED;
218-
log.trace("acceptHandshakeAsClient - Matching extension found: " + extension.toString());
218+
log.trace("acceptHandshakeAsClient - Matching extension found: {}",extension);
219219
break;
220220
}
221221
}
@@ -225,7 +225,7 @@ public HandshakeState acceptHandshakeAsClient( ClientHandshake request, ServerHa
225225
if( knownProtocol.acceptProvidedProtocol( requestedProtocol ) ) {
226226
protocol = knownProtocol;
227227
protocolState = HandshakeState.MATCHED;
228-
log.trace("acceptHandshakeAsClient - Matching protocol found: " + protocol.toString());
228+
log.trace("acceptHandshakeAsClient - Matching protocol found: {}",protocol);
229229
break;
230230
}
231231
}
@@ -343,7 +343,7 @@ public Draft copyInstance() {
343343
@Override
344344
public ByteBuffer createBinaryFrame( Framedata framedata ) {
345345
getExtension().encodeFrame( framedata );
346-
log.trace( "afterEnconding(" + framedata.getPayloadData().remaining() + "): {" + ( framedata.getPayloadData().remaining() > 1000 ? "too big to display" : new String( framedata.getPayloadData().array() ) ) + '}' );
346+
log.trace( "afterEnconding({}): {}" , framedata.getPayloadData().remaining(), ( framedata.getPayloadData().remaining() > 1000 ? "too big to display" : new String( framedata.getPayloadData().array() ) ) );
347347
return createByteBufferFromFramedata( framedata );
348348
}
349349

@@ -478,7 +478,7 @@ public Framedata translateSingleFrame( ByteBuffer buffer ) throws IncompleteExce
478478
frame.setPayload( payload );
479479
getExtension().isFrameValid(frame);
480480
getExtension().decodeFrame(frame);
481-
log.trace( "afterDecoding(" + frame.getPayloadData().remaining() + "): {" + ( frame.getPayloadData().remaining() > 1000 ? "too big to display" : new String( frame.getPayloadData().array() ) ) + '}' );
481+
log.trace( "afterDecoding({}): {}", frame.getPayloadData().remaining(), ( frame.getPayloadData().remaining() > 1000 ? "too big to display" : new String( frame.getPayloadData().array() ) ) );
482482
frame.isValid();
483483
return frame;
484484
}
@@ -695,7 +695,7 @@ public void processFrame( WebSocketImpl webSocketImpl, Framedata frame ) throws
695695
try {
696696
webSocketImpl.getWebSocketListener().onWebsocketMessage( webSocketImpl, Charsetfunctions.stringUtf8( current_continuous_frame.getPayloadData() ) );
697697
} catch ( RuntimeException e ) {
698-
log.error( "Runtime exception during onWebsocketMessage", e );
698+
log.error( "Runtime exception during onWebsocketMessage: {}", e );
699699
webSocketImpl.getWebSocketListener().onWebsocketError( webSocketImpl, e );
700700
}
701701
} else if( current_continuous_frame.getOpcode() == Opcode.BINARY ) {
@@ -704,7 +704,7 @@ public void processFrame( WebSocketImpl webSocketImpl, Framedata frame ) throws
704704
try {
705705
webSocketImpl.getWebSocketListener().onWebsocketMessage( webSocketImpl, current_continuous_frame.getPayloadData() );
706706
} catch ( RuntimeException e ) {
707-
log.error( "Runtime exception during onWebsocketMessage", e );
707+
log.error( "Runtime exception during onWebsocketMessage: {}", e );
708708
webSocketImpl.getWebSocketListener().onWebsocketError( webSocketImpl, e );
709709
}
710710
}

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,15 @@ public void run() {
471471
try {
472472
selector.close();
473473
} catch ( IOException e ) {
474-
log.error( "IOException during selector.close", e );
474+
log.error( "IOException during selector.close: {}", e );
475475
onError( null, e );
476476
}
477477
}
478478
if( server != null ) {
479479
try {
480480
server.close();
481481
} catch ( IOException e ) {
482-
log.error( "IOException during server.close", e );
482+
log.error( "IOException during server.close: {}", e );
483483
onError( null, e );
484484
}
485485
}
@@ -532,13 +532,13 @@ private void handleIOException( SelectionKey key, WebSocket conn, IOException ex
532532
} catch ( IOException e ) {
533533
// there is nothing that must be done here
534534
}
535-
log.warn("Connection closed because of " + ex);
535+
log.warn("Connection closed because of exception: {}",ex);
536536
}
537537
}
538538
}
539539

540540
private void handleFatal( WebSocket conn, Exception e ) {
541-
log.error( "Shutdown due to fatal error", e );
541+
log.error( "Shutdown due to fatal error: {}", e );
542542
onError( conn, e );
543543
//Shutting down WebSocketWorkers, see #222
544544
if( decoders != null ) {
@@ -552,11 +552,11 @@ private void handleFatal( WebSocket conn, Exception e ) {
552552
try {
553553
stop();
554554
} catch ( IOException e1 ) {
555-
log.error( "Error during shutdown", e1 );
555+
log.error( "Error during shutdown: {}", e1 );
556556
onError( null, e1 );
557557
} catch ( InterruptedException e1 ) {
558558
Thread.currentThread().interrupt();
559-
log.error( "Interrupt during stop", e );
559+
log.error( "Interrupt during stop: {}", e );
560560
onError( null, e1 );
561561
}
562562
}
@@ -611,7 +611,7 @@ protected boolean removeConnection( WebSocket ws ) {
611611
removed = this.connections.remove( ws );
612612
} else {
613613
//Don't throw an assert error if the ws is not in the list. e.g. when the other endpoint did not send any handshake. see #512
614-
log.warn("Removing connection which is not in the connections collection! Possible no handshake recieved! " + ws);
614+
log.warn("Removing connection which is not in the connections collection! Possible no handshake recieved! {}", ws);
615615
}
616616
}
617617
if( isclosed.get() && connections.size() == 0 ) {
@@ -890,8 +890,7 @@ public WebSocketWorker() {
890890
setUncaughtExceptionHandler( new UncaughtExceptionHandler() {
891891
@Override
892892
public void uncaughtException( Thread t, Throwable e ) {
893-
log.error("Uncaught exception in thread \""
894-
+ t.getName() + "\":", e);
893+
log.error("Uncaught exception in thread {}: {}", t.getName(), e);
895894
}
896895
} );
897896
}
@@ -912,7 +911,7 @@ public void run() {
912911
try {
913912
ws.decode( buf );
914913
} catch(Exception e){
915-
log.error("Error while reading from remote connection: ", e);
914+
log.error("Error while reading from remote connection: {}", e);
916915
}
917916

918917
finally {

0 commit comments

Comments
 (0)