views:

35

answers:

3

While upgrading sun application server 8.2 to a new patch level an exception occurred and I don't know why. Following a code snippet from a servlet:

public void init() throws ServletException
{
    Properties reqProperties = new Properties();
    try
    {
        reqProperties.load( this.getClass().getResourceAsStream( "/someFile.properties" ) );
    }
    catch( IOException e )
    {
        e.printStackTrace();
    }
 .......

The file does exists on the classpath and in previous patch versions it worked just fine. but now when deploying this result in a exception. The stack trace:

[#|2010-04-14T16:43:48.208+0200|WARNING|sun-appserver-ee8.2|javax.enterprise.system.core.classloading|_ThreadID=11;|loader.InputStreams with no valid reference is closed java.lang.Throwable at com.sun.enterprise.loader.EJBClassLoader$SentinelInputStream.(EJBClassLoader.java:1172) at com.sun.enterprise.loader.EJBClassLoader.getResourceAsStream(EJBClassLoader.java:858) at java.lang.Class.getResourceAsStream(Class.java:1998) at a.package.TestServlet.init(TestServlet.java:44) at javax.servlet.GenericServlet.init(GenericServlet.java:261) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:592) at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAsPrivileged(Subject.java:517) at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282) at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165) at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:118) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1093) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:931) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4183) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4535) at com.sun.enterprise.web.WebModule.start(WebModule.java:241) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1086) at org.apache.catalina.core.StandardHost.start(StandardHost.java:847) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1086) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:483) at org.apache.catalina.startup.Embedded.start(Embedded.java:894) at com.sun.enterprise.web.WebContainer.start(WebContainer.java:741) at com.sun.enterprise.web.HttpServiceWebContainer.startInstance(HttpServiceWebContainer.java:963) at com.sun.enterprise.web.HttpServiceWebContainerLifecycle.onStartup(HttpServiceWebContainerLifecycle.java:50) at com.sun.enterprise.server.ApplicationServer.onStartup(ApplicationServer.java:300) at com.sun.enterprise.server.PEMain.run(PEMain.java:308) at com.sun.enterprise.server.PEMain.main(PEMain.java:221) |#]

I've no idea what could be the problem anyone have any idea? (note that I changed some names in the code and stacktrace)

A: 

Are you sure it throws an exception? We get warnings like this in Glassfish all the time. The EJBClassLoader uses a throwable to dump the stack trace so it may look like an exception to you.

EJBClassLoader wraps all streams with sentinels. This warning simply tells you that your stream is not closed. You can safely ignore it. To get rid of the warning, you have to close the stream after you use it.

ZZ Coder
A: 

you should always close inputstreams after using:

public void init() throws ServletException{
    InputStream str = null;
    Properties reqProperties = new Properties();
try{
    str = this.getClass().getResourceAsStream( "/someFile.properties" );
    reqProperties.load( str );
}catch( IOException e ){
    e.printStackTrace();
}finally{
    if(str!=null){try{str.close()}catch(IOException e){e.printStackTrace();}}
}

btw, the finally clause can be made a lot simpler using apache commons / io:

finally{
    IOUtils.closeQuietly(str);
}
seanizer
A: 

I suggest you have a search at Valid Reference for this issue...

ali