numerous findbugs inspired cleanups

This commit is contained in:
Greg Wilkins 2011-11-15 11:22:35 +11:00
parent a82d429e0b
commit 722f390800
34 changed files with 98 additions and 73 deletions

View File

@ -193,7 +193,7 @@ public class HttpGeneratorClientTest
}
private static final String[] headers= { "Content-Type","Content-Length","Connection","Transfer-Encoding","Other"};
private class TR
private static class TR
{
private String[] values=new String[headers.length];
private String body;

View File

@ -138,7 +138,7 @@ public class HttpGeneratorTest
}
private static final String[] headers= { "Content-Type","Content-Length","Connection","Transfer-Encoding","Other"};
private class TR
private static class TR
{
private int _code;
private String _body;

View File

@ -46,7 +46,6 @@ public class BufferDateCache extends DateCache
public synchronized Buffer formatBuffer(long date)
{
String d = super.format(date);
//noinspection StringEquality
if (d==_last)
return _buffer;
_last=d;

View File

@ -462,13 +462,15 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
*/
private void updateKey()
{
int current_ops=-1;
final boolean changed;
synchronized (this)
{
int current_ops=-1;
if (getChannel().isOpen())
{
boolean read_interest = _readBlocked || (!_dispatched && !_connection.isSuspended());
boolean write_interest= _writeBlocked || (!_dispatched && !_writable);
_interestOps =
((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0)
| ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0);
@ -482,9 +484,10 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
LOG.ignore(e);
}
}
changed=_interestOps!=current_ops;
}
if(_interestOps != current_ops)
if(changed)
{
_selectSet.addChange(this);
_selectSet.wakeup();

View File

@ -658,7 +658,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
while (now<end)
{
process(null,null);
synchronized (this)
synchronized (SslConnection.this)
{
if (_unwrapBuf!=null && _unwrapBuf.hasContent())
break;
@ -789,9 +789,16 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
public String toString()
{
Buffer i=_inbound;
Buffer o=_outbound;
Buffer u=_unwrapBuf;
Buffer i;
Buffer o;
Buffer u;
synchronized(SslConnection.this)
{
i=_inbound;
o=_outbound;
u=_unwrapBuf;
}
return "SSL:"+_endp+" "+_engine.getHandshakeStatus()+" i/u/o="+(i==null?0:i.length())+"/"+(u==null?0:u.length())+"/"+(o==null?0:o.length()+(_oshut?" oshut":""));
}

View File

@ -358,7 +358,11 @@ public abstract class AbstractConnector extends HttpBuffers implements Connector
/* ------------------------------------------------------------ */
public void join() throws InterruptedException
{
Thread[] threads = _acceptorThread;
Thread[] threads;
synchronized(this)
{
threads= _acceptorThread;
}
if (threads != null)
for (int i = 0; i < threads.length; i++)
if (threads[i] != null)

View File

@ -629,7 +629,7 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
*/
@Override
protected void doStart() throws Exception
protected synchronized void doStart() throws Exception
{
if (_logDateFormat != null)
{

View File

@ -576,7 +576,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
*/
public boolean isShutdown()
{
return !_shutdown;
synchronized (this)
{
return !_shutdown;
}
}
/* ------------------------------------------------------------ */
@ -602,7 +605,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
*/
public boolean isAvailable()
{
return _available;
synchronized (this)
{
return _available;
}
}
/* ------------------------------------------------------------ */
@ -666,7 +672,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
// defers the calling of super.doStart()
startContext();
_availability = _shutdown?__SHUTDOWN:_available?__AVAILABLE:__UNAVAILABLE;
synchronized(this)
{
_availability = _shutdown?__SHUTDOWN:_available?__AVAILABLE:__UNAVAILABLE;
}
}
finally
{

View File

@ -110,10 +110,6 @@ public class DefaultHandler extends AbstractHandler
response.setContentType(MimeTypes.TEXT_HTML);
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500);
String uri=request.getRequestURI();
uri=StringUtil.replace(uri,"<","&lt;");
uri=StringUtil.replace(uri,">","&gt;");
writer.write("<HTML>\n<HEAD>\n<TITLE>Error 404 - Not Found");
writer.write("</TITLE>\n<BODY>\n<H2>Error 404 - Not Found.</H2>\n");

View File

@ -281,9 +281,9 @@ public class GzipHandler extends HandlerWrapper
return new GzipResponseWrapper(request, response)
{
{
setMimeTypes(GzipHandler.this._mimeTypes);
setBufferSize(GzipHandler.this._bufferSize);
setMinGzipSize(GzipHandler.this._minGzipSize);
super.setMimeTypes(GzipHandler.this._mimeTypes);
super.setBufferSize(GzipHandler.this._bufferSize);
super.setMinGzipSize(GzipHandler.this._minGzipSize);
}
@Override

View File

@ -100,12 +100,6 @@ public class MovedContextHandler extends ContextHandler
{
if (_newContextURL==null)
return;
String url = _newContextURL;
if (!_discardPathInfo && request.getPathInfo()!=null)
url=URIUtil.addPaths(url, request.getPathInfo());
if (!_discardQuery && request.getQueryString()!=null)
url+="?"+request.getQueryString();
String path=_newContextURL;
if (!_discardPathInfo && request.getPathInfo()!=null)
@ -117,7 +111,9 @@ public class MovedContextHandler extends ContextHandler
if (!_discardQuery && request.getQueryString()!=null)
{
location.append('?');
location.append(request.getQueryString());
String q=request.getQueryString();
q=q.replaceAll("\r\n?&=","!");
location.append(q);
}
response.setHeader(HttpHeaders.LOCATION,location.toString());

View File

@ -309,7 +309,6 @@ public class ResourceHandler extends AbstractHandler
}
else
{
included = Boolean.FALSE;
servletPath = request.getServletPath();
pathInfo = request.getPathInfo();
}

View File

@ -207,7 +207,7 @@ public class BlockingChannelConnector extends AbstractNIOConnector
{
try
{
close();
super.close();
}
catch (IOException e)
{
@ -221,7 +221,7 @@ public class BlockingChannelConnector extends AbstractNIOConnector
if (!getThreadPool().dispatch(this))
{
LOG.warn("dispatch failed for {}",_connection);
BlockingChannelEndPoint.this.close();
super.close();
}
}
@ -302,13 +302,17 @@ public class BlockingChannelConnector extends AbstractNIOConnector
catch (HttpException e)
{
LOG.debug("BAD", e);
try{BlockingChannelEndPoint.this.close();}
try{super.close();}
catch(IOException e2){LOG.ignore(e2);}
}
catch(ThreadDeath e)
{
throw e;
}
catch(Throwable e)
{
LOG.warn("handle failed",e);
try{BlockingChannelEndPoint.this.close();}
try{super.close();}
catch(IOException e2){LOG.ignore(e2);}
}
finally

View File

@ -92,10 +92,15 @@ public class SelectChannelConnector extends AbstractNIOConnector
@Override
public void accept(int acceptorID) throws IOException
{
ServerSocketChannel server = _acceptChannel;
ServerSocketChannel server;
synchronized(this)
{
server = _acceptChannel;
}
if (server!=null && server.isOpen() && _manager.isStarted())
{
SocketChannel channel = _acceptChannel.accept();
SocketChannel channel = server.accept();
channel.configureBlocking(false);
Socket socket = channel.socket();
configure(socket);
@ -141,7 +146,7 @@ public class SelectChannelConnector extends AbstractNIOConnector
}
/* ------------------------------------------------------------ */
public Object getConnection()
public synchronized Object getConnection()
{
return _acceptChannel;
}
@ -299,11 +304,15 @@ public class SelectChannelConnector extends AbstractNIOConnector
public void dump(Appendable out, String indent) throws IOException
{
out.append(String.valueOf(this)).append("\n");
ServerSocketChannel channel=_acceptChannel;
ServerSocketChannel channel;
synchronized (this)
{
channel=_acceptChannel;
}
if (channel==null)
AggregateLifeCycle.dump(out,indent,Arrays.asList(new Object[]{null,"CLOSED",_manager}));
else
AggregateLifeCycle.dump(out,indent,Arrays.asList(new Object[]{_acceptChannel,_acceptChannel.isOpen()?"OPEN":"CLOSED",_manager}));
AggregateLifeCycle.dump(out,indent,Arrays.asList(new Object[]{channel,channel.isOpen()?"OPEN":"CLOSED",_manager}));
}
/* ------------------------------------------------------------ */

View File

@ -457,7 +457,10 @@ public abstract class AbstractSession implements AbstractSessionManager.SessionI
/* ------------------------------------------------------------- */
protected void cookieSet()
{
_cookieSet=_accessed;
synchronized (this)
{
_cookieSet=_accessed;
}
}
/* ------------------------------------------------------------ */

View File

@ -78,7 +78,7 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
}
/* ------------------------------------------------------------ */
public void setRandom(Random random)
public synchronized void setRandom(Random random)
{
_random=random;
_weakRandom=false;

View File

@ -54,8 +54,6 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
OutputStream os=client.getOutputStream();
InputStream is=client.getInputStream();
String content="Wibble";
byte[] contentB=content.getBytes("utf-8");
os.write((
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
@ -64,7 +62,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
os.flush();
long start = System.currentTimeMillis();
String in = IO.toString(is);
IO.toString(is);
Thread.sleep(300);
assertEquals(-1, is.read());
@ -97,7 +95,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
os.flush();
long start = System.currentTimeMillis();
String in = IO.toString(is);
IO.toString(is);
Thread.sleep(300);
assertEquals(-1, is.read());

View File

@ -151,8 +151,7 @@ public class DumpHandler extends AbstractHandler
String val=request.getParameter("CookieVal");
val=val.replaceAll("[ \n\r=<>]","?");
Cookie cookie=
new Cookie(cookie_name.trim(),
request.getParameter("CookieVal"));
new Cookie(cookie_name.trim(),val);
if ("Clear Cookie".equals(cookie_action))
cookie.setMaxAge(0);
response.addCookie(cookie);

View File

@ -28,7 +28,7 @@ public class EncodedHttpURITest
{
String url = "http://www.foo.com/ma\u00F1ana";
byte[] asISO = url.getBytes("ISO-8859-1");
String str = new String(asISO, "ISO-8859-1");
new String(asISO, "ISO-8859-1");
//use a non UTF-8 charset as the encoding and url-escape as per
//http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars

View File

@ -123,7 +123,7 @@ public class HttpConnectionTest
int offset=0;
offset = checkContains(response,offset,"HTTP/1.1 200");
offset = checkContains(response,offset,"/R1");
checkContains(response,offset,"/R1");
}
@Test
@ -365,7 +365,7 @@ public class HttpConnectionTest
"5;\015\012"+
"12345\015\012"+
"0;\015\012\015\012");
offset = checkContains(response,offset,"Connection: close");
checkContains(response,offset,"Connection: close");
}
catch (Exception e)
{
@ -394,7 +394,7 @@ public class HttpConnectionTest
"Cookie: "+cookie+"\n"+
"\015\012"
);
offset = checkContains(response, offset, "HTTP/1.1 413");
checkContains(response, offset, "HTTP/1.1 413");
}
catch(Exception e)
{
@ -423,7 +423,7 @@ public class HttpConnectionTest
request.append("\015\012");
response = connector.getResponses(request.toString());
offset = checkContains(response, offset, "HTTP/1.1 413");
checkContains(response, offset, "HTTP/1.1 413");
}
@Test
@ -469,7 +469,7 @@ public class HttpConnectionTest
"\015\012"
);
offset = checkContains(response, offset, "HTTP/1.1 500");
checkContains(response, offset, "HTTP/1.1 500");
}
catch(Exception e)
{
@ -548,7 +548,7 @@ public class HttpConnectionTest
response=connector.getResponses("CONNECT www.webtide.com:8080 HTTP/1.1\n"+
"Host: myproxy:8888\015\012"+
"\015\012");
offset = checkContains(response,offset,"HTTP/1.1 200");
checkContains(response,offset,"HTTP/1.1 200");
}
catch (Exception e)

View File

@ -160,7 +160,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
// Read the response.
String response=readResponse(client);
assertTrue(true); // nothing checked yet.
assertTrue (response.indexOf("200")>0);
}
finally
{
@ -556,8 +556,8 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
// read and check the times are < 999ms
String[] times=in.readLine().split(",");
// Assert.assertTrue(Integer.valueOf(t).intValue()<999);
for (String t: times)
Assert.assertTrue(Integer.valueOf(t).intValue()<999);
// read the EOF chunk
@ -587,7 +587,8 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
// read and check the times are < 999ms
times=in.readLine().split(",");
//Assert.assertTrue(t,Integer.valueOf(t).intValue()<999);
for (String t: times)
Assert.assertTrue(t,Integer.valueOf(t).intValue()<999);
// check close
Assert.assertTrue(in.readLine()==null);
@ -1060,7 +1061,6 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
AvailableHandler ah=new AvailableHandler();
configureServer(ah);
long start=System.currentTimeMillis();
Socket client=newSocket(HOST,_connector.getLocalPort());
try
{

View File

@ -189,7 +189,7 @@ public class HttpServerTestFixture
}
// Create a trust manager that does not validate certificate chains
public static TrustManager[] __trustAllCerts = new TrustManager[] {
public final static TrustManager[] __trustAllCerts = new TrustManager[] {
new X509TrustManager(){
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
@ -203,7 +203,7 @@ public class HttpServerTestFixture
}
};
public static HostnameVerifier __hostnameverifier = new HostnameVerifier()
public final static HostnameVerifier __hostnameverifier = new HostnameVerifier()
{
public boolean verify(String hostname, SSLSession session)
{

View File

@ -160,7 +160,6 @@ public class ResponseTest
{
AbstractHttpConnection connection = new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer());
Request request = connection.getRequest();
Response response = connection.getResponse();

View File

@ -365,7 +365,6 @@ public class StressTest
if (__tests.length!=bodies)
System.err.println("responses=\n"+response+"\n---");
assertEquals(name,__tests.length,bodies);
bodies = count(response,"HTTP/1.1 200 OK");
long bind=connected-start;
long flush=(written-connected)/__tests.length;
@ -461,7 +460,6 @@ public class StressTest
response.setStatus(200);
response.getOutputStream().print("DATA "+request.getPathInfo()+"\n\n");
baseRequest.setHandled(true);
long end=System.currentTimeMillis();
_latencies[4].add(new Long(System.currentTimeMillis()-start));

View File

@ -216,7 +216,7 @@ public class SslRenegotiateTest
private void doWrap() throws Exception
{
SSLEngineResult result =_engine.wrap(_outAppB,_outPacketB);
_engine.wrap(_outAppB,_outPacketB);
// System.err.println("wrapped "+result.bytesConsumed()+" to "+result.bytesProduced());
_outPacketB.flip();
while (_outPacketB.hasRemaining())

View File

@ -15,6 +15,7 @@
package org.eclipse.jetty.server.ssl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.FileInputStream;
import java.io.IOException;
@ -37,6 +38,7 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@ -129,6 +131,7 @@ public class SslUploadTest
InputStream in = socket.getInputStream();
String response = IO.toString(in);
assertTrue (response.indexOf("200")>0);
// System.err.println(response);
long end = System.nanoTime();

View File

@ -104,7 +104,7 @@ public class DateCache
/** Set the timezone.
* @param tz TimeZone
*/
public void setTimeZone(TimeZone tz)
public synchronized void setTimeZone(TimeZone tz)
{
setTzFormatString(tz);
if( _locale != null )
@ -145,7 +145,7 @@ public class DateCache
}
/* ------------------------------------------------------------ */
private void setTzFormatString(final TimeZone tz )
private synchronized void setTzFormatString(final TimeZone tz )
{
int zIndex = _formatString.indexOf( "ZZZ" );
if( zIndex >= 0 )

View File

@ -330,7 +330,7 @@ public class StringUtil
/* ------------------------------------------------------------ */
public static boolean isUTF8(String charset)
{
return charset==__UTF8||__UTF8.equalsIgnoreCase(charset)||__UTF8Alt.equalsIgnoreCase(charset);
return __UTF8.equalsIgnoreCase(charset)||__UTF8Alt.equalsIgnoreCase(charset);
}

View File

@ -43,7 +43,7 @@ import org.eclipse.jetty.util.log.Logger;
*
* @see java.net.URLEncoder
*/
public class UrlEncoded extends MultiMap
public class UrlEncoded extends MultiMap implements Cloneable
{
private static final Logger LOG = Log.getLogger(UrlEncoded.class);

View File

@ -373,7 +373,7 @@ public class JSON
@Deprecated
public void appendJSON(final StringBuffer buffer, Convertible converter)
{
appendJSON((StringBuffer)buffer,converter);
appendJSON((Appendable)buffer,converter);
}
/* ------------------------------------------------------------ */

View File

@ -151,7 +151,6 @@ public class JarResource extends URLResource
JarInputStream jin = new JarInputStream(is);
JarEntry entry;
boolean shouldExtract;
String directoryCanonicalPath = directory.getCanonicalPath()+"/";
while((entry=jin.getNextJarEntry())!=null)
{
String entryName = entry.getName();

View File

@ -113,7 +113,7 @@ public class JSONPojoConvertorFactoryTest
Map<String,Object> bz = (Map<String,Object>)br.get("baz");
Map<String,Object> f = (Map<String,Object>)bz.get("foo");
assertTrue(f != null);
Object[] bazs = (Object[])br.get("bazs");
assertTrue(bazs.length==2);
assertEquals(((Map)bazs[0]).get("message"), "baz0");

View File

@ -203,7 +203,7 @@ public class JSONTest
public void testZeroByte()
{
String withzero="\u0000";
String json = JSON.toString(withzero);
JSON.toString(withzero);
}
/* ------------------------------------------------------------ */

View File

@ -135,7 +135,7 @@ public class LifeCycleListenerTest
lifecycle.stop();
assertFalse("The stopping event occurred", listener.stopping);
}
private class TestLifeCycle extends AbstractLifeCycle
private static class TestLifeCycle extends AbstractLifeCycle
{
Exception cause;