tommccann tommccann - 1 year ago 93
Java Question

Field not used warning in Eclipse

I'm implementing a login filter in a JSF application. I have a private field called config. Eclipse displays a warning "The value of the field AuthenticationFilter.config is not used" despite the field being referred to in the init and destroy methods. Am I doing something wrong here or is Eclipse a bit confused?

Here's the AuthenticationFilter class:



import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AuthenticationFilter implements Filter {

private FilterConfig config;

public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
if (((HttpServletRequest) req).getSession().getAttribute(
LoginBean.AUTH_KEY) == null) {
((HttpServletResponse) resp).sendRedirect("../login.xhtml");
} else {
chain.doFilter(req, resp);

public void init(FilterConfig config) throws ServletException {
this.config = config;

public void destroy() {
config = null;

Answer Source

Initialising and destroying config aren't "using" them - the compiler is telling you that you've got a variable that you're wasting memory and time initialising and destroying when it isn't being used anywhere.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download