diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/GZIPContentDecoder.java b/jetty-http/src/main/java/org/eclipse/jetty/http/GZIPContentDecoder.java index 7df8d821e14..ccadf2d3b16 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/GZIPContentDecoder.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/GZIPContentDecoder.java @@ -417,7 +417,9 @@ public class GZIPContentDecoder implements Destroyable */ public void release(ByteBuffer buffer) { - if (_pool!=null && buffer!=BufferUtil.EMPTY_BUFFER) + @SuppressWarnings("ReferenceEquality") + boolean isBufferEmpty = (buffer!=BufferUtil.EMPTY_BUFFER); + if (_pool!=null && isBufferEmpty) _pool.release(buffer); } } diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java index 93fe67b3dbf..adffa595b44 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java @@ -276,9 +276,12 @@ public class HttpField public boolean isSameName(HttpField field) { + @SuppressWarnings("ReferenceEquality") + boolean sameObject = (field==this); + if (field==null) return false; - if (field==this) + if (sameObject) return true; if (_header!=null && _header==field.getHeader()) return true; diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java index ce1c9c2a047..ec5baedb32d 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java @@ -202,7 +202,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint throw new ClosedChannelException(); ByteBuffer in = _inQ.peek(); - if (BufferUtil.hasContent(in) || in==EOF) + if (BufferUtil.hasContent(in) || isEOF(in)) execute(_runFillable); } } @@ -224,7 +224,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint boolean fillable=false; try(Locker.Lock lock = _locker.lock()) { - if (_inQ.peek()==EOF) + if (isEOF(_inQ.peek())) throw new RuntimeIOException(new EOFException()); boolean was_empty=_inQ.isEmpty(); if (in==null) @@ -248,7 +248,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint boolean fillable=false; try(Locker.Lock lock = _locker.lock()) { - if (_inQ.peek()==EOF) + if (isEOF(_inQ.peek())) throw new RuntimeIOException(new EOFException()); boolean was_empty=_inQ.isEmpty(); if (in==null) @@ -415,7 +415,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint break; ByteBuffer in= _inQ.peek(); - if (in==EOF) + if (isEOF(in)) { filled=-1; break; @@ -549,4 +549,16 @@ public class ByteArrayEndPoint extends AbstractEndPoint return String.format("%s[q=%d,q[0]=%s,o=%s]",super.toString(),q,b,o); } + /* ------------------------------------------------------------ */ + /** + * Compares a ByteBuffer Object to EOF by Reference + * @param buffer the input ByteBuffer to be compared to EOF + * @return Whether the reference buffer is equal to that of EOF + */ + private static boolean isEOF(ByteBuffer buffer) + { + @SuppressWarnings("ReferenceEquality") + boolean is_EOF = (buffer==EOF); + return is_EOF; + } } diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java index 06fc0ddb155..8673f263965 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java @@ -626,8 +626,12 @@ public class SslConnection extends AbstractConnection // We also need an app buffer, but can use the passed buffer if it is big enough ByteBuffer app_in; + boolean used_passed_buffer = false; if (BufferUtil.space(buffer) > _sslEngine.getSession().getApplicationBufferSize()) + { app_in = buffer; + used_passed_buffer = true; + } else if (_decryptedInput == null) app_in = _decryptedInput = _bufferPool.acquire(_sslEngine.getSession().getApplicationBufferSize(), _decryptedDirectBuffers); else @@ -729,7 +733,7 @@ public class SslConnection extends AbstractConnection // another call to fill() or flush(). if (unwrapResult.bytesProduced() > 0) { - if (app_in == buffer) + if (used_passed_buffer) return unwrapResult.bytesProduced(); return BufferUtil.append(buffer,_decryptedInput); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java index bee4f951c92..70545de2016 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelOverHttp.java @@ -427,7 +427,10 @@ public class HttpChannelOverHttp extends HttpChannel implements HttpParser.Reque if (LOG.isDebugEnabled()) LOG.debug("upgrade {} {}", this, _upgrade); - if (_upgrade != PREAMBLE_UPGRADE_H2C && (_connection == null || !_connection.contains("upgrade"))) + @SuppressWarnings("ReferenceEquality") + boolean isUpgraded_H2C = (_upgrade == PREAMBLE_UPGRADE_H2C); + + if (!isUpgraded_H2C && (_connection == null || !_connection.contains("upgrade"))) throw new BadMessageException(HttpStatus.BAD_REQUEST_400); // Find the upgrade factory @@ -464,7 +467,7 @@ public class HttpChannelOverHttp extends HttpChannel implements HttpParser.Reque // Send 101 if needed try { - if (_upgrade != PREAMBLE_UPGRADE_H2C) + if (!isUpgraded_H2C) sendResponse(new MetaData.Response(HttpVersion.HTTP_1_1, HttpStatus.SWITCHING_PROTOCOLS_101, response101, 0), null, true); } catch (IOException e) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 5003436dcc3..63930e8bd3c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -143,6 +143,18 @@ public class Request implements HttpServletRequest private static final MultiMap NO_PARAMS = new MultiMap<>(); + /* ------------------------------------------------------------ */ + /** + * Compare inputParameters to NO_PARAMS by Reference + * @param inputParameters The parameters to compare to NO_PARAMS + * @return True if the inputParameters reference is equal to NO_PARAMS otherwise False + */ + private static boolean isNoParams(MultiMap inputParameters) { + @SuppressWarnings("ReferenceEquality") + boolean is_no_params = (inputParameters==NO_PARAMS); + return is_no_params; + } + /* ------------------------------------------------------------ */ /** * Obtain the base {@link Request} instance of a {@link ServletRequest}, by @@ -397,9 +409,9 @@ public class Request implements HttpServletRequest } // Do parameters need to be combined? - if (_queryParameters==NO_PARAMS || _queryParameters.size()==0) + if (isNoParams(_queryParameters) || _queryParameters.size()==0) _parameters=_contentParameters; - else if (_contentParameters==NO_PARAMS || _contentParameters.size()==0) + else if (isNoParams(_contentParameters) || _contentParameters.size()==0) _parameters=_queryParameters; else { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ResponseWriter.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ResponseWriter.java index 7a964e4feb5..c13b6145892 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ResponseWriter.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ResponseWriter.java @@ -456,11 +456,29 @@ public class ResponseWriter extends PrintWriter { try { + + if(l==null) + l = _locale; + synchronized (lock) { isOpen(); - if ((_formatter == null) || (_formatter.locale() != l)) + + if(_formatter == null) + { _formatter = new Formatter(this, l); + } + else if(_formatter.locale() != null) + { + if(!_formatter.locale().equals(l)) + _formatter = new Formatter(this, l); + } + else + { + if(l != null) + _formatter = new Formatter(this, l); + } + _formatter.format(l, format, args); } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index 3dddc7c732b..9d0021130a7 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -63,6 +63,7 @@ import org.eclipse.jetty.server.session.Session; import org.eclipse.jetty.server.session.SessionData; import org.eclipse.jetty.server.session.SessionHandler; import org.eclipse.jetty.toolchain.test.AdvancedRunner; +import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.util.thread.TimerScheduler; @@ -112,10 +113,13 @@ public class ResponseTest private Server _server; private HttpChannel _channel; + private ByteBuffer _content = BufferUtil.allocate(16*1024); @Before public void init() throws Exception { + BufferUtil.clear(_content); + _server = new Server(); Scheduler _scheduler = new TimerScheduler(); HttpConfiguration config = new HttpConfiguration(); @@ -139,6 +143,12 @@ public class ResponseTest @Override public void send(MetaData.Response info, boolean head, ByteBuffer content, boolean lastContent, Callback callback) { + if(BufferUtil.hasContent(content)) + { + BufferUtil.append(_content, content); + } + + if (_channelError==null) callback.succeeded(); else @@ -172,6 +182,7 @@ public class ResponseTest { return false; } + }); } @@ -364,6 +375,54 @@ public class ResponseTest assertTrue(response.toString().indexOf("charset=utf-8") > 0); } + @Test + public void testLocaleFormat() throws Exception + { + Response response = getResponse(); + + ContextHandler context = new ContextHandler(); + context.addLocaleEncoding(Locale.ENGLISH.toString(), "ISO-8859-1"); + context.addLocaleEncoding(Locale.ITALIAN.toString(), "ISO-8859-2"); + response.getHttpChannel().getRequest().setContext(context.getServletContext()); + + response.setLocale(java.util.Locale.ITALIAN); + + PrintWriter out = response.getWriter(); + + out.format("TestA1 %,.2f%n", 1234567.89); + out.format("TestA2 %,.2f%n", 1234567.89); + + out.format((java.util.Locale)null,"TestB1 %,.2f%n", 1234567.89); + out.format((java.util.Locale)null,"TestB2 %,.2f%n", 1234567.89); + + out.format(Locale.ENGLISH,"TestC1 %,.2f%n", 1234567.89); + out.format(Locale.ENGLISH,"TestC2 %,.2f%n", 1234567.89); + + out.format(Locale.ITALIAN,"TestD1 %,.2f%n", 1234567.89); + out.format(Locale.ITALIAN,"TestD2 %,.2f%n", 1234567.89); + + out.close(); + + /* Test A */ + Assert.assertThat(BufferUtil.toString(_content),Matchers.containsString("TestA1 1.234.567,89")); + Assert.assertThat(BufferUtil.toString(_content),Matchers.containsString("TestA2 1.234.567,89")); + + /* Test B */ + Assert.assertThat(BufferUtil.toString(_content),Matchers.containsString("TestB1 1.234.567,89")); + Assert.assertThat(BufferUtil.toString(_content),Matchers.containsString("TestB2 1.234.567,89")); + + /* Test C */ + Assert.assertThat(BufferUtil.toString(_content),Matchers.containsString("TestC1 1,234,567.89")); + Assert.assertThat(BufferUtil.toString(_content),Matchers.containsString("TestC2 1,234,567.89")); + + /* Test D */ + Assert.assertThat(BufferUtil.toString(_content),Matchers.containsString("TestD1 1.234.567,89")); + Assert.assertThat(BufferUtil.toString(_content),Matchers.containsString("TestD2 1.234.567,89")); + + + } + + @Test public void testContentTypeCharacterEncoding() throws Exception { diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java index cf57826e53a..ad47828d840 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java @@ -514,7 +514,9 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory, Welc if ((_welcomeServlets || _welcomeExactServlets) && welcome_servlet==null) { MappedResource entry=_servletHandler.getMappedServlet(welcome_in_context); - if (entry!=null && entry.getResource()!=_defaultHolder && + @SuppressWarnings("ReferenceEquality") + boolean isDefaultHolder = (entry.getResource()!=_defaultHolder); + if (entry!=null && isDefaultHolder && (_welcomeServlets || (_welcomeExactServlets && entry.getPathSpec().getDeclaration().equals(welcome_in_context)))) welcome_servlet=welcome_in_context; diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index ba920f6d5c9..4ddaf61793f 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -1513,7 +1513,9 @@ public class ServletHandler extends ScopedHandler boolean found = false; for (ServletHolder s:_servlets) { - if (s == holder) + @SuppressWarnings("ReferenceEquality") + boolean foundServletHolder = (s == holder); + if (foundServletHolder) found = true; } return found; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Fields.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Fields.java index 9c360b4b8cc..74d00b128fe 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Fields.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Fields.java @@ -253,7 +253,9 @@ public class Fields implements Iterable public boolean equals(Field that, boolean caseSensitive) { - if (this == that) + @SuppressWarnings("ReferenceEquality") + boolean isCurrentObject = (this == that); + if (isCurrentObject) return true; if (that == null) return false; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java index 363721175cf..455857647a2 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java @@ -221,7 +221,7 @@ public class UrlEncoded extends MultiMap implements Cloneable if (charset==null) charset=ENCODING; - if (charset==StandardCharsets.UTF_8) + if (StandardCharsets.UTF_8.equals(charset)) { decodeUtf8To(content,0,content.length(),map); return; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java index 383144a9933..9817d493482 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java @@ -211,7 +211,9 @@ public class StdErrLog extends AbstractLogger */ public StdErrLog(String name, Properties props) { - if (props!=null && props!=Log.__props) + @SuppressWarnings("ReferenceEquality") + boolean sameObject = (props!=Log.__props); + if (props!=null && sameObject) Log.__props.putAll(props); _name = name == null?"":name; _abbrevname = condensePackageString(this._name); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java index 71b2151d779..296dd6a8dfe 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java @@ -416,7 +416,9 @@ public class FileResource extends Resource return false; FileResource f=(FileResource)o; - return f._file == _file || (null != _file && _file.equals(f._file)); + @SuppressWarnings("ReferenceEquality") + boolean sameFile = f._file==_file; + return sameFile || (null != _file && _file.equals(f._file)); } /* ------------------------------------------------------------ */ diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java b/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java index 8792924340d..862d3bd7605 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java @@ -95,7 +95,9 @@ public abstract class Credential implements Serializable */ protected static boolean stringEquals(String known, String unknown) { - if (known == unknown) + @SuppressWarnings("ReferenceEquality") + boolean sameObject = (known == unknown); + if (sameObject) return true; if (known == null || unknown == null) return false; diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java index 863013791fc..576d37d2f5e 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/ClasspathPattern.java @@ -696,9 +696,9 @@ public class ClasspathPattern extends AbstractSet LOG.debug("match {} from {} byName={} byLocation={} in {}",clazz,location,byName,byLocation,this); // Combine the tri-state match of both IncludeExclude Sets - boolean included = byName==Boolean.TRUE || byLocation==Boolean.TRUE + boolean included = Boolean.TRUE.equals(byName) || Boolean.TRUE.equals(byLocation) || (byName==null && !_patterns.hasIncludes() && byLocation==null && !_locations.hasIncludes()); - boolean excluded = byName==Boolean.FALSE || byLocation==Boolean.FALSE; + boolean excluded = Boolean.FALSE.equals(byName) || Boolean.FALSE.equals(byLocation); return included && !excluded; } catch (Exception e) @@ -737,9 +737,9 @@ public class ClasspathPattern extends AbstractSet } // Combine the tri-state match of both IncludeExclude Sets - boolean included = byName==Boolean.TRUE || byLocation==Boolean.TRUE + boolean included = Boolean.TRUE.equals(byName) || Boolean.TRUE.equals(byLocation) || (byName==null && !_patterns.hasIncludes() && byLocation==null && !_locations.hasIncludes()); - boolean excluded = byName==Boolean.FALSE || byLocation==Boolean.FALSE; + boolean excluded = Boolean.FALSE.equals(byName) || Boolean.FALSE.equals(byLocation); return included && !excluded; }