You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2016/04/23 07:32:55 UTC

[Bug 59369] New: classloader getResourceAsStream throws exception instead of returning NULL.

https://bz.apache.org/bugzilla/show_bug.cgi?id=59369

            Bug ID: 59369
           Summary: classloader getResourceAsStream throws exception
                    instead of returning NULL.
           Product: Tomcat 9
           Version: 9.0.0.M4
          Hardware: PC
                OS: Mac OS X 10.1
            Status: NEW
          Severity: major
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: steven@twelvetone.tv

When using JavaMail and Tomcat 9.0.0.M4

JavaMail checks for META-INF/javamail.providers and
META-INF/javamail.address.map resources on the class loader of the
javax.mail.Authenticator class.  If the resources do not exist, a null pointer
exception is thrown instead of returning null.

http://docs.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String)

Session.getResourceAsStream only catches a PrivilegedActionException.  This
causes Session.getInstance to fail.

A fix/workaround involves either 
1. putting empty META-INF entries in the jar, 
or 
2. catching the NPE in Session.getResourceAsStream and re-throwing it as an IO
exception.

java.lang.NullPointerException
        at
org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1089)
        at java.lang.Class.getResourceAsStream(Class.java:2223)
        at javax.mail.Session$4.run(Session.java:1232)
        at javax.mail.Session$4.run(Session.java:1230)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.mail.Session.getResourceAsStream(Session.java:1229)
        at javax.mail.Session.loadResource(Session.java:1123)
        at javax.mail.Session.loadAllResources(Session.java:1203)
        at javax.mail.Session.loadProviders(Session.java:934)
        at javax.mail.Session.<init>(Session.java:224)
        at javax.mail.Session.getInstance(Session.java:251)


JavaMail Workaround

try {
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<InputStream>() {
            public InputStream run() throws IOException {
                try {
                    return c.getResourceAsStream(name);
                } catch (Exception e) {
                    throw new IOException(e);
                }
            }
            }
        );
    } catch (PrivilegedActionException e) {
        throw (IOException)e.getException();
    }
    }

filed on JavaMail as well 
https://kenai.com/bugzilla/show_bug.cgi?id=7356

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 59369] classloader getResourceAsStream throws exception instead of returning NULL.

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59369

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #1 from Mark Thomas <ma...@apache.org> ---
Already fixed for 9.0.0.M5 with r1736489.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org