0

When I run a web application with Java 8, Tomcat 8, Netbeans 8, it runs perfectly fine. Running the same application with Netbeans 11, the below error occurs, even though it is still Java 8, Tomcat 8 in Netbeans 11.

This is the tomcat error log.

Mar 05, 2020 9:30:40 AM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter DatabaseCheckFilter
java.lang.RuntimeException: 
    at filters.DatabaseCheckFilter.<init>(DatabaseCheckFilter.java:1)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:424)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

The code for the class is

package filters;

import dataaccesslayer.DatabaseCheck;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import utilities.exceptions.ExceptionLogger;

public class DatabaseCheckFilter implements Filter {

    // The filter configuration object we are associated with.  If
    // this value is null, this filter instance is not currently
    // configured.
    private FilterConfig filterConfig = null;

    public DatabaseCheckFilter() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        boolean databaseError = false;
        try {
            DatabaseCheck check = new DatabaseCheck();
            databaseError = check.Check(response);
            if (databaseError == true) {
                RequestDispatcher fd=request.getRequestDispatcher("/error/unavailable.jsp");
                fd.forward(request,response);
            }
            else {
                chain.doFilter(request, response);
            }
        } catch (Exception exception) {
            ExceptionLogger.logException(exception);
        }
    }

    public FilterConfig getFilterConfig() {
        return (this.filterConfig);
    }

    public void setFilterConfig(FilterConfig filterConfig) {
        this.filterConfig = filterConfig;
    }

    public void destroy() {        
    }

    public void init(FilterConfig filterConfig) {
        this.filterConfig = filterConfig;
    }
}

An extract from the web.xml is

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <filter>
        <filter-name>UserInfoFilter</filter-name>
        <filter-class>filters.UserInfoFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>UserInfoFilter</filter-name>
        <url-pattern>/scheduler.jsp</url-pattern>
    </filter-mapping>
    <filter>
        <filter-name>DatabaseCheckFilter</filter-name>
        <filter-class>filters.DatabaseCheckFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>DatabaseCheckFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
webber55
  • 329
  • 4
  • 13
  • 1
    You sure that stacktrace doesn't continue with a "Caused by:", showing the real reason it failed? --- Also, can you show the code for `DatabaseCheckFilter`? – Andreas Feb 27 '20 at 16:37
  • 1
    It's difficult to say anything much without the source of the `DatabaseCheckFilter` class, which looks to be one of yours rather than a built-in Java class or one from a commonly-used library. The best guess I can come up with is that this class has a catch block similar to the following in it: `catch (Exception e) { throw new RuntimeException(e.getMessage()); }`, and this catch block is catching a NullPointerException, which usually doesn't have a message. – Luke Woodward Feb 27 '20 at 17:49
  • I've added a full stack trace as well as code from the class and the web.xml file – webber55 Mar 05 '20 at 10:00
  • Please ensure that you're not shipping some very old servlet-api.jar withing your .war file. Better yet: either use servlet-api.jar from your latest tomcat distribution to compile your web application or use some relatively modern version. – vbezhenar Mar 05 '20 at 10:56
  • I'm using the servlet-api.jar file that is included with Tomcat 8 – webber55 Mar 05 '20 at 16:27

2 Answers2

1

Netbeans 11+ version solved this problem.

vaibhavkhot
  • 502
  • 3
  • 3
0

Running the just released Netbeans 11.3 fixed this problem.

webber55
  • 329
  • 4
  • 13