Skip to content

Commit

Permalink
Cleanup many warnings from ee10 and ee11 servlet
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed May 16, 2024
1 parent 7f1823e commit 09f3adc
Show file tree
Hide file tree
Showing 54 changed files with 394 additions and 487 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.slf4j.LoggerFactory;

/**
* AbstractHolder
*
* Base class for all servlet-related classes that may be lazily instantiated (eg servlet, filter,
* listener), and/or require metadata to be held regarding their origin
* (web.xml, annotation, programmatic api etc).
Expand Down Expand Up @@ -86,7 +84,7 @@ public void doStart()
{
//if no class already loaded and no classname, make permanently unavailable
if (_class == null && (_className == null || _className.isEmpty()))
throw new UnavailableException("No class in holder " + toString());
throw new UnavailableException("No class in holder " + this);

//try to load class
if (_class == null)
Expand All @@ -100,7 +98,7 @@ public void doStart()
catch (Exception e)
{
LOG.warn("Unable to load class {}", _className, e);
throw new UnavailableException("Class loading error for holder " + toString());
throw new UnavailableException("Class loading error for holder " + this);
}
}
}
Expand Down Expand Up @@ -173,27 +171,31 @@ protected void illegalStateIfContextStarted()

protected void setInstance(T instance)
{
try (AutoLock l = lock())
try (AutoLock ignored = lock())
{
_instance = instance;
if (instance == null)
setHeldClass(null);
else
setHeldClass((Class<T>)instance.getClass());
{
@SuppressWarnings("unchecked")
Class<? extends T> clazz = (Class<? extends T>)instance.getClass();
setHeldClass(clazz);
}
}
}

protected T getInstance()
{
try (AutoLock l = lock())
try (AutoLock ignored = lock())
{
return _instance;
}
}

protected T createInstance() throws Exception
{
try (AutoLock l = lock())
try (AutoLock ignored = lock())
{
ServletContext ctx = getServletContext();
if (ctx == null)
Expand Down Expand Up @@ -241,7 +243,7 @@ public ServletContextHandler getServletContextHandler()
*/
public boolean isInstance()
{
try (AutoLock l = lock())
try (AutoLock ignored = lock())
{
return _instance != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public interface ContentProducer
/**
* Fail all content currently available in this {@link ContentProducer} instance
* as well as in the underlying {@link Content.Source}.
*
* This call is always non-blocking.
* Doesn't change state.
* @return true if EOF was reached.
Expand All @@ -50,7 +49,6 @@ public interface ContentProducer

/**
* Get the byte count produced by the underlying {@link Content.Source}.
*
* This call is always non-blocking.
* Doesn't change state.
* @return the byte count produced by the underlying {@link Content.Source}.
Expand All @@ -60,7 +58,6 @@ public interface ContentProducer
/**
* Get the byte count that can immediately be read from this
* {@link ContentProducer} instance or the underlying {@link Content.Source}.
*
* This call is always non-blocking.
* Doesn't change state.
* @return the available byte count.
Expand All @@ -70,7 +67,6 @@ public interface ContentProducer
/**
* Check if this {@link ContentProducer} instance contains some
* content chunk without querying the underlying {@link Content.Source}.
*
* This call is always non-blocking.
* Doesn't change state.
* Doesn't query the HttpChannel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public HttpURI getHttpURI()
}
}

private class IncludeResponse extends ServletCoreResponse
private static class IncludeResponse extends ServletCoreResponse
{
public IncludeResponse(Request coreRequest, HttpServletResponse httpServletResponse)
{
Expand Down Expand Up @@ -256,7 +256,6 @@ public void include(ServletRequest servletRequest, ServletResponse servletRespon
{
HttpServletRequest httpServletRequest = (servletRequest instanceof HttpServletRequest) ? ((HttpServletRequest)servletRequest) : new ServletRequestHttpWrapper(servletRequest);
HttpServletResponse httpServletResponse = (servletResponse instanceof HttpServletResponse) ? (HttpServletResponse)servletResponse : new ServletResponseHttpWrapper(servletResponse);
ServletContextResponse servletContextResponse = ServletContextResponse.getServletContextResponse(servletResponse);

IncludeRequest includeRequest = new IncludeRequest(httpServletRequest);
IncludeResponse includeResponse = new IncludeResponse(includeRequest, httpServletResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public <T> T decorate(T o)
{
try
{
return (T)_decorate.invoke(_object, o);
@SuppressWarnings("unchecked")
T decorated = (T)_decorate.invoke(_object, o);
return decorated;
}
catch (Throwable t)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,12 +747,9 @@ public Enumeration<String> getAttributeNames()

private class ErrorRequest extends ParameterRequestWrapper
{
private final HttpServletRequest _httpServletRequest;

public ErrorRequest(HttpServletRequest httpRequest)
{
super(httpRequest);
_httpServletRequest = httpRequest;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,11 @@ public ErrorHandler()

public boolean errorPageForMethod(String method)
{
switch (method)
return switch (method)
{
case "GET":
case "POST":
case "HEAD":
return true;
default:
return false;
}
case "GET", "POST", "HEAD" -> true;
default -> false;
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void doStart()
@Override
public void initialize() throws Exception
{
try (AutoLock l = lock())
try (AutoLock ignored = lock())
{
if (_filter != null)
return;
Expand Down Expand Up @@ -140,7 +140,7 @@ public void initialize() throws Exception
@Override
protected Filter createInstance() throws Exception
{
try (AutoLock l = lock())
try (AutoLock ignored = lock())
{
Filter filter = super.createInstance();
if (filter == null)
Expand Down Expand Up @@ -392,7 +392,7 @@ public void destroy()
@Override
public String toString()
{
return String.format("%s:%s", this.getClass().getSimpleName(), _filter.toString());
return String.format("%s:%s", this.getClass().getSimpleName(), _filter);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,14 @@ public static DispatcherType dispatch(String type)
*/
public static int dispatch(DispatcherType type)
{
switch (type)
return switch (type)
{
case REQUEST:
return REQUEST;
case ASYNC:
return ASYNC;
case FORWARD:
return FORWARD;
case INCLUDE:
return INCLUDE;
case ERROR:
return ERROR;
default:
throw new IllegalStateException(type.toString());
}
case REQUEST -> REQUEST;
case ASYNC -> ASYNC;
case FORWARD -> FORWARD;
case INCLUDE -> INCLUDE;
case ERROR -> ERROR;
};
}

/**
Expand All @@ -94,21 +87,15 @@ public static int dispatch(DispatcherType type)
*/
public static DispatcherType dispatch(int type)
{
switch (type)
return switch (type)
{
case REQUEST:
return DispatcherType.REQUEST;
case ASYNC:
return DispatcherType.ASYNC;
case FORWARD:
return DispatcherType.FORWARD;
case INCLUDE:
return DispatcherType.INCLUDE;
case ERROR:
return DispatcherType.ERROR;
default:
throw new IllegalArgumentException(Integer.toString(type));
}
case REQUEST -> DispatcherType.REQUEST;
case ASYNC -> DispatcherType.ASYNC;
case FORWARD -> DispatcherType.FORWARD;
case INCLUDE -> DispatcherType.INCLUDE;
case ERROR -> DispatcherType.ERROR;
default -> throw new IllegalArgumentException(Integer.toString(type));
};
}

private int _dispatches = DEFAULT;
Expand All @@ -132,9 +119,9 @@ boolean appliesTo(String path, int type)
{
if (appliesTo(type))
{
for (int i = 0; i < _pathSpecs.length; i++)
for (String pathSpec : _pathSpecs)
{
if (_pathSpecs[i] != null && ServletPathSpec.match(_pathSpecs[i], path, true))
if (pathSpec != null && ServletPathSpec.match(pathSpec, path, true))
return true;
}
}
Expand All @@ -152,10 +139,10 @@ boolean appliesTo(String path, int type)
boolean appliesTo(int type)
{
FilterHolder holder = _holder;
if (_holder == null)
if (holder == null)
return false;
if (_dispatches == 0)
return type == REQUEST || type == ASYNC && (_holder != null && _holder.isAsyncSupported());
return type == REQUEST || type == ASYNC && holder.isAsyncSupported();
return (_dispatches & type) != 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.slf4j.LoggerFactory;

/**
* Holder
*
* Specialization of AbstractHolder for servlet-related classes that
* have init-params etc
*
Expand All @@ -41,7 +39,7 @@ public abstract class Holder<T> extends BaseHolder<T>
{
private static final Logger LOG = LoggerFactory.getLogger(Holder.class);

private final Map<String, String> _initParams = new HashMap<String, String>(3);
private final Map<String, String> _initParams = new HashMap<>(3);
private String _displayName;
private boolean _asyncSupported;
private String _name;
Expand Down Expand Up @@ -69,15 +67,11 @@ public String getDisplayName()

public String getInitParameter(String param)
{
if (_initParams == null)
return null;
return (String)_initParams.get(param);
return _initParams.get(param);
}

public Enumeration<String> getInitParameterNames()
{
if (_initParams == null)
return Collections.enumeration(Collections.EMPTY_LIST);
return Collections.enumeration(_initParams.keySet());
}

Expand All @@ -96,7 +90,7 @@ public String getName()
@Override
protected void setInstance(T instance)
{
try (AutoLock l = lock())
try (AutoLock ignored = lock())
{
super.setInstance(instance);
if (getName() == null)
Expand Down Expand Up @@ -277,7 +271,7 @@ public Set<String> setInitParameters(Map<String, String> initParameters)
if (Holder.this.getInitParameter(entry.getKey()) != null)
{
if (clash == null)
clash = new HashSet<String>();
clash = new HashSet<>();
clash.add(entry.getKey());
}
}
Expand Down
Loading

0 comments on commit 09f3adc

Please sign in to comment.