Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » bundle.getResources("") throw NPE
bundle.getResources("") throw NPE [message #547584] Mon, 19 July 2010 05:29 Go to next message
Will Yao is currently offline Will YaoFriend
Messages: 11
Registered: July 2010
Junior Member
Hi all:

I create a servlet listener, like this:
public class SampleListener implements ServletContextListener {
	private static final Logger logger = LoggerFactory.getLogger(SampleListener.class);

	public void contextInitialized(ServletContextEvent sce) {
		Bundle currentBundle = FrameworkUtil.getBundle(getClass());
		try {
			Enumeration<URL> resources2 = currentBundle.getResources("");
			logger.debug("resources2: {}", resources2);
			Enumeration<URL> resources1 = Thread.currentThread().getContextClassLoader().getResources("");
			logger.debug("resources1: {}", resources1);

		} catch (Exception e) {
			logger.error(e.getMessage(), e);


	public void contextDestroyed(ServletContextEvent sce) {}

When the webapp deploy to virgo and starting the listener, this throw a NPE:
sample.servlet.SampleListener               name java.lang.NullPointerException: name
        at java.util.jar.JarFile.getEntry(
        at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBundleFileWrapperFactoryHook$FileResourceEnforcingBundleFile.doesJarEntryReallyExist(
        at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBundleFileWrapperFactoryHook$FileResourceEnforcingBundleFile.getLocalURLForEntry(
        at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBundleFileWrapperFactoryHook$FileResourceEnforcingBundleFile.doGetResourceURL(
        at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBundleFileWrapperFactoryHook$FileResourceEnforcingBundleFile.getResourceURL(
        at org.eclipse.osgi.baseadaptor.bundlefile.BundleFileWrapperChain.getResourceURL(
        at org.eclipse.virgo.kernel.userregion.internal.equinox.TransformedManifestProvidingBundleFileWrapper$TransformedManifestProvidingBundleFile.getResourceURL(
        at org.eclipse.osgi.baseadaptor.bundlefile.BundleFileWrapperChain.getResourceURL(
        at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findResourceImpl(
        at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalResources(
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalResources(
        at org.eclipse.osgi.internal.loader.BundleLoader.findLocalResources(
        at org.eclipse.osgi.internal.loader.BundleLoader.findResources(
        at org.eclipse.osgi.internal.loader.BundleLoader.getResources(
        at org.eclipse.osgi.framework.internal.core.BundleHost.getResources(

Is this a bug? And any one can help me?

Thank you!
Re: bundle.getResources("") throw NPE [message #547635 is a reply to message #547584] Mon, 19 July 2010 08:35 Go to previous messageGo to next message
Will Yao is currently offline Will YaoFriend
Messages: 11
Registered: July 2010
Junior Member
Hi all:

I modified the org/eclipse/virgo/osgi/extensions/equinox/hooks/ExtendedBund class, and this solved the problem. But I do not know whether this will affect other features.

diff --git a/org.eclipse.virgo.osgi.extensions.equinox/src/main/java/org/eclipse/virgo/osgi/extensions/equinox/hooks/ b/org
index 04af22b..0b88279 100644
--- a/org.eclipse.virgo.osgi.extensions.equinox/src/main/java/org/eclipse/virgo/osgi/extensions/equinox/hooks/
+++ b/org.eclipse.virgo.osgi.extensions.equinox/src/main/java/org/eclipse/virgo/osgi/extensions/equinox/hooks/
@@ -180,7 +180,10 @@ final class ExtendedBundleFileWrapperFactoryHook implements BundleFileWrapperFac
                 if (connection instanceof JarURLConnection) {
                     JarURLConnection jarURLConnection = (JarURLConnection) connection;
                     jarFile = jarURLConnection.getJarFile();
-                    if (jarFile != null && jarFile.getEntry(jarURLConnection.getEntryName()) != null) {
+                    String entryName = jarURLConnection.getEntryName();
+                    if (null == entryName) { // the jar file
+                        entryExists = true;
+                    } else if (jarFile != null && jarFile.getEntry(entryName) != null) {
                        entryExists = true;

Re: bundle.getResources("") throw NPE [message #547980 is a reply to message #547635] Tue, 20 July 2010 10:22 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn NormingtonFriend
Messages: 1222
Registered: July 2009
Senior Member
This looks like a bug. Please would you raise a bugzilla against Virgo and point at this thread.
Re: bundle.getResources("") throw NPE [message #548379 is a reply to message #547635] Wed, 21 July 2010 15:49 Go to previous message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

I have made this change and committed it back. I didn't use your patch exactly as you sent it as I think the logic wasn't quite right. I've added in the following.

jarFile = jarURLConnection.getJarFile();
String entryName = jarURLConnection.getEntryName();
if (entryName != null && jarFile != null && jarFile.getEntry(entryName) != null) {
    entryExists = true;

I'm happy to be convinced otherwise but if the URL doesn't specify a Jar Entry in the first place I don't think we should say it is present.


Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Previous Topic:Custom Log-Appender
Next Topic:bundle.getResources("") throw NPE
Goto Forum:

Current Time: Thu Jun 21 22:24:13 GMT 2018

Powered by FUDForum. Page generated in 0.01871 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top