found additional ReferenceEquality warnings which have been resolved

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2018-03-06 14:28:11 +11:00
parent 480c0e718a
commit 020ebde77c
27 changed files with 100 additions and 37 deletions

View File

@ -81,6 +81,18 @@ public class HttpContent implements Callback, Closeable
this.iterator = provider == null ? Collections.<ByteBuffer>emptyIterator() : provider.iterator();
}
/**
*
* @param buffer
* @return whether the input buffer has been closed
*/
private static boolean isBufferClosed(ByteBuffer buffer)
{
@SuppressWarnings("ReferenceEquality")
boolean bufferClosed = (buffer == CLOSE);
return bufferClosed;
}
/**
* @return whether there is any content at all
*/
@ -177,6 +189,7 @@ public class HttpContent implements Callback, Closeable
/**
* @return whether the cursor has been advanced past the {@link #isLast() last} position.
*/
@SuppressWarnings("ReferenceEquality")
public boolean isConsumed()
{
return buffer == AFTER;
@ -187,7 +200,7 @@ public class HttpContent implements Callback, Closeable
{
if (isConsumed())
return;
if (buffer == CLOSE)
if (isBufferClosed(buffer))
return;
if (iterator instanceof Callback)
((Callback)iterator).succeeded();
@ -198,7 +211,7 @@ public class HttpContent implements Callback, Closeable
{
if (isConsumed())
return;
if (buffer == CLOSE)
if (isBufferClosed(buffer))
return;
if (iterator instanceof Callback)
((Callback)iterator).failed(x);

View File

@ -204,7 +204,10 @@ public class HttpRequest implements Request
{
if (uri == null)
uri = buildURI(true);
return uri == NULL_URI ? null : uri;
@SuppressWarnings("ReferenceEquality")
boolean isNullURI = (uri == NULL_URI);
return isNullURI ? null : uri;
}
@Override

View File

@ -321,10 +321,10 @@ public class HttpSenderOverHTTP extends HttpSender
private void release()
{
ByteBufferPool bufferPool = httpClient.getByteBufferPool();
if (headerBuffer != BufferUtil.EMPTY_BUFFER)
if (!BufferUtil.isTheEmptyBuffer(headerBuffer))
bufferPool.release(headerBuffer);
headerBuffer = null;
if (chunkBuffer != BufferUtil.EMPTY_BUFFER)
if (!BufferUtil.isTheEmptyBuffer(chunkBuffer))
bufferPool.release(chunkBuffer);
chunkBuffer = null;
contentBuffer = null;

View File

@ -589,6 +589,7 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
public ByteBuffer current;
@Override
@SuppressWarnings("ReferenceEquality")
public boolean hasNext()
{
if (current == null)

View File

@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@ -311,10 +312,12 @@ public class DeploymentManager extends ContainerLifeCycle
*/
public Collection<App> getApps(Node node)
{
Objects.requireNonNull(node);
List<App> ret = new ArrayList<>();
for (AppEntry entry : _apps)
{
if (entry.lifecyleNode == node)
if (node.equals(entry.lifecyleNode))
{
ret.add(entry.app);
}

View File

@ -28,7 +28,9 @@ public final class Edge
public Edge(Node from, Node to)
{
if (from==null || to==null || from==to)
@SuppressWarnings("ReferenceEquality")
boolean sameObject = (from==to);
if (from==null || to==null || sameObject)
throw new IllegalArgumentException("from "+from+" to "+to);
_from = from;
_to = to;
@ -72,11 +74,25 @@ public final class Edge
return _from;
}
public boolean isFromNode(Node node)
{
@SuppressWarnings("ReferenceEquality")
boolean isFromNode_ = (_from == node);
return isFromNode_;
}
public Node getTo()
{
return _to;
}
public boolean isToNode(Node node)
{
@SuppressWarnings("ReferenceEquality")
boolean isToNode_ = (_to == node);
return isToNode_;
}
@Override
public String toString()
{

View File

@ -40,7 +40,7 @@ public class Graph
addNode(toNode=edge.getTo());
// replace edge with normalized edge
if (edge.getFrom()!=fromNode || edge.getTo()!=toNode)
if (!edge.isFromNode(fromNode) || !edge.isToNode(toNode))
edge=new Edge(fromNode,toNode);
this._edges.add(edge);
@ -129,7 +129,7 @@ public class Graph
for (Edge edge : this._edges)
{
if ((edge.getFrom() == node) || (edge.getTo() == node))
if (edge.isFromNode(node) || edge.isToNode(node))
{
fromedges.add(edge);
}
@ -151,7 +151,7 @@ public class Graph
for (Edge edge : this._edges)
{
if (edge.getFrom() == from)
if (edge.isFromNode(from))
{
fromedges.add(edge);
}
@ -192,7 +192,9 @@ public class Graph
*/
public Path getPath(Node from, Node to)
{
if (from == to)
@SuppressWarnings("ReferenceEquality")
boolean sameObject = (from==to);
if (sameObject)
{
return new Path();
}

View File

@ -74,7 +74,7 @@ public class DeploymentManagerMBean extends ObjectMBean
List<String> ret = new ArrayList<>();
for (DeploymentManager.AppEntry entry : _manager.getAppEntries())
{
if (entry.getLifecyleNode() == node)
if (node.equals(entry.getLifecyleNode()))
{
ret.add(toRef(entry.getApp()));
}

View File

@ -127,7 +127,9 @@ public class HttpConnectionOverFCGI extends AbstractConnection implements Connec
private void releaseBuffer(ByteBuffer buffer)
{
assert this.buffer == buffer;
@SuppressWarnings("ReferenceEquality")
boolean isCurrentBuffer = (this.buffer == buffer);
assert(isCurrentBuffer);
HttpClient client = destination.getHttpClient();
ByteBufferPool bufferPool = client.getByteBufferPool();
bufferPool.release(buffer);

View File

@ -418,8 +418,8 @@ public class GZIPContentDecoder implements Destroyable
public void release(ByteBuffer buffer)
{
@SuppressWarnings("ReferenceEquality")
boolean isTheEmptyBuffer = (buffer!=BufferUtil.EMPTY_BUFFER);
if (_pool!=null && isTheEmptyBuffer)
boolean isTheEmptyBuffer = (buffer==BufferUtil.EMPTY_BUFFER);
if (_pool!=null && !isTheEmptyBuffer)
_pool.release(buffer);
}
}

View File

@ -2025,6 +2025,7 @@ public class HttpParserTest
Assert.assertEquals(null, _bad);
}
@Test
@SuppressWarnings("ReferenceEquality")
public void testCachedField() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(

View File

@ -131,6 +131,7 @@ public class HpackContextTest
assertNull(ctx.get("name"));
}
@Test
@SuppressWarnings("ReferenceEquality")
public void testGetAddStatic()
{
HpackContext ctx = new HpackContext(4096);

View File

@ -29,6 +29,7 @@ import java.util.Arrays;
import org.eclipse.jetty.io.ByteBufferPool.Bucket;
import org.junit.Test;
@SuppressWarnings("ReferenceEquality")
public class ArrayByteBufferPoolTest
{
@Test
@ -113,6 +114,7 @@ public class ArrayByteBufferPoolTest
}
@Test
@SuppressWarnings("ReferenceEquality")
public void testAcquireReleaseAcquire() throws Exception
{
ArrayByteBufferPool bufferPool = new ArrayByteBufferPool(10,100,1000);

View File

@ -115,7 +115,7 @@ public class ValidUrlRule extends Rule
LOG.debug("{} {} {} {}", Character.charCount(codepoint), codepoint, block, Character.isISOControl(codepoint));
return (!Character.isISOControl(codepoint)) && block != null && block != Character.UnicodeBlock.SPECIALS;
return (!Character.isISOControl(codepoint)) && block != null && !Character.UnicodeBlock.SPECIALS.equals(block);
}
public String toString()

View File

@ -470,11 +470,6 @@ public class ResponseWriter extends PrintWriter
{
_formatter = new Formatter(this, locale);
}
else if(_formatter.locale()==null)
{
if(locale != null)
_formatter = new Formatter(this, locale);
}
else if (!_formatter.locale().equals(locale))
{
_formatter = new Formatter(this, locale);

View File

@ -381,7 +381,7 @@ public class DoSFilter implements Filter
// or if we were woken up we insist or we fail.
Boolean throttled = (Boolean)request.getAttribute(__THROTTLED);
long throttleMs = getThrottleMs();
if (throttled != Boolean.TRUE && throttleMs > 0)
if (Boolean.FALSE.equals(throttled) && throttleMs > 0)
{
int priority = getPriority(request, tracker);
request.setAttribute(__THROTTLED, Boolean.TRUE);
@ -399,7 +399,7 @@ public class DoSFilter implements Filter
}
Boolean resumed = (Boolean)request.getAttribute(_resumed);
if (resumed == Boolean.TRUE)
if (Boolean.TRUE.equals(resumed))
{
// We were resumed, we wait for the next pass.
_passes.acquire();
@ -444,7 +444,7 @@ public class DoSFilter implements Filter
{
ServletRequest candidate = asyncContext.getRequest();
Boolean suspended = (Boolean)candidate.getAttribute(_suspended);
if (suspended == Boolean.TRUE)
if (Boolean.TRUE.equals(suspended))
{
if (LOG.isDebugEnabled())
LOG.debug("Resuming {}", request);

View File

@ -171,7 +171,7 @@ public class QoSFilter implements Filter
{
request.setAttribute(_suspended, Boolean.FALSE);
Boolean resumed = (Boolean)request.getAttribute(_resumed);
if (resumed == Boolean.TRUE)
if (Boolean.TRUE.equals(resumed))
{
_passes.acquire();
accepted = true;
@ -222,7 +222,7 @@ public class QoSFilter implements Filter
{
ServletRequest candidate = asyncContext.getRequest();
Boolean suspended = (Boolean)candidate.getAttribute(_suspended);
if (suspended == Boolean.TRUE)
if (Boolean.TRUE.equals(suspended))
{
candidate.setAttribute(_resumed, Boolean.TRUE);
asyncContext.dispatch();

View File

@ -305,7 +305,7 @@ public class Modules implements Iterable<Module>
{
for (Module p:providers)
{
if (p!=module && p.isEnabled())
if (!p.equals(module) && p.isEnabled())
{
// If the already enabled module is transitive and this enable is not
if (p.isTransitive() && !transitive)
@ -364,8 +364,8 @@ public class Modules implements Iterable<Module>
}
// If a provider is already enabled, then add a transitive enable
if (providers.stream().filter(Module::isEnabled).count()!=0)
providers.stream().filter(m->m.isEnabled()&&m!=module).forEach(m->enable(newlyEnabled,m,"transitive provider of "+dependsOn+" for "+module.getName(),true));
if (providers.stream().filter(Module::isEnabled).count()>0)
providers.stream().filter(m->m.isEnabled()&&!m.equals(module)).forEach(m->enable(newlyEnabled,m,"transitive provider of "+dependsOn+" for "+module.getName(),true));
else
{
// Is there an obvious default?

View File

@ -238,6 +238,17 @@ public class BufferUtil
}
}
/**
* @param buf the buffer to check
* @return true if buf is equal to EMPTY_BUFFER
*/
public static boolean isTheEmptyBuffer(ByteBuffer buf)
{
@SuppressWarnings("ReferenceEquality")
boolean isTheEmptyBuffer_ = (buf == EMPTY_BUFFER);
return isTheEmptyBuffer_;
}
/* ------------------------------------------------------------ */
/** Check for an empty or null buffer.
* @param buf the buffer to check

View File

@ -251,11 +251,10 @@ public class Fields implements Iterable<Fields.Field>
this.values = Collections.unmodifiableList(list);
}
@SuppressWarnings("ReferenceEquality")
public boolean equals(Field that, boolean caseSensitive)
{
@SuppressWarnings("ReferenceEquality")
boolean isThisInstance = (this == that);
if (isThisInstance)
if (this == that)
return true;
if (that == null)
return false;

View File

@ -407,6 +407,7 @@ public class FileResource extends Resource
* @return <code>true</code> of the object <code>o</code> is a {@link FileResource} pointing to the same file as this resource.
*/
@Override
@SuppressWarnings("ReferenceEquality")
public boolean equals( Object o)
{
if (this == o)
@ -416,9 +417,7 @@ public class FileResource extends Resource
return false;
FileResource f=(FileResource)o;
@SuppressWarnings("ReferenceEquality")
boolean sameFile = f._file==_file;
return sameFile || (null != _file && _file.equals(f._file));
return f._file==_file || (null != _file && _file.equals(f._file));
}
/* ------------------------------------------------------------ */

View File

@ -297,6 +297,7 @@ public class BufferUtilTest
@Test
@SuppressWarnings("ReferenceEquality")
public void testEnsureCapacity() throws Exception
{
ByteBuffer b = BufferUtil.toBuffer("Goodbye Cruel World");

View File

@ -40,6 +40,7 @@ public class DateCacheTest
/* ------------------------------------------------------------ */
@Test
@Slow
@SuppressWarnings("ReferenceEquality")
public void testDateCache() throws Exception
{
//@WAS: Test t = new Test("org.eclipse.jetty.util.DateCache");

View File

@ -36,6 +36,7 @@ import static org.junit.Assert.assertTrue;
public class StringUtilTest
{
@Test
@SuppressWarnings("ReferenceEquality")
public void testAsciiToLowerCase()
{
String lc="\u0690bc def 1\u06903";
@ -88,6 +89,7 @@ public class StringUtilTest
}
@Test
@SuppressWarnings("ReferenceEquality")
public void testReplace()
{
String s="\u0690bc \u0690bc \u0690bc";
@ -100,6 +102,7 @@ public class StringUtilTest
}
@Test
@SuppressWarnings("ReferenceEquality")
public void testUnquote()
{
String uq =" not quoted ";
@ -112,9 +115,10 @@ public class StringUtilTest
@Test
@SuppressWarnings("ReferenceEquality")
public void testNonNull()
{
String nn="";
String nn="non empty string";
assertTrue(nn==StringUtil.nonNull(nn));
assertEquals("",StringUtil.nonNull(null));
}

View File

@ -193,6 +193,7 @@ public class TopologicalSortTest
}
}
@SuppressWarnings("ReferenceEquality")
private int indexOf(String[] list,String s)
{
for (int i=0;i<list.length;i++)

View File

@ -45,6 +45,13 @@ public class MessageInputStream extends InputStream implements MessageAppender
private final long timeoutMs;
private ByteBuffer activeBuffer = null;
private static boolean isBufferEOF(ByteBuffer buf)
{
@SuppressWarnings("ReferenceEquality")
boolean isBufferEOF_ = (buf==EOF);
return isBufferEOF_;
}
public MessageInputStream()
{
this(-1);
@ -166,7 +173,7 @@ public class MessageInputStream extends InputStream implements MessageAppender
}
}
if (activeBuffer == EOF)
if (isBufferEOF(activeBuffer))
{
if (LOG.isDebugEnabled())
LOG.debug("Reached EOF");

View File

@ -85,6 +85,7 @@ public abstract class AbstractSessionInvalidateCreateScavengeTest extends Abstra
}
@Test
@SuppressWarnings("ReferenceEquality")
public void testSessionScavenge() throws Exception
{
String contextPath = "/";