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);

	@Override
	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);
		}

	}

	@Override
	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.zip.ZipFile.getEntry(ZipFile.java:144)
        at java.util.jar.JarFile.getEntry(JarFile.java:206)
        at sun.net.www.protocol.jar.URLJarFile.getEntry(URLJarFile.java:107)
        at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBundleFileWrapperFactoryHook$FileResourceEnforcingBundleFile.doesJarEntryReallyExist(ExtendedBundleFileWrapperFactoryHook.java:183)
        at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBundleFileWrapperFactoryHook$FileResourceEnforcingBundleFile.getLocalURLForEntry(ExtendedBundleFileWrapperFactoryHook.java:168)
        at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBundleFileWrapperFactoryHook$FileResourceEnforcingBundleFile.doGetResourceURL(ExtendedBundleFileWrapperFactoryHook.java:154)
        at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBundleFileWrapperFactoryHook$FileResourceEnforcingBundleFile.getResourceURL(ExtendedBundleFileWrapperFactoryHook.java:148)
        at org.eclipse.osgi.baseadaptor.bundlefile.BundleFileWrapperChain.getResourceURL(BundleFileWrapperChain.java:64)
        at org.eclipse.virgo.kernel.userregion.internal.equinox.TransformedManifestProvidingBundleFileWrapper$TransformedManifestProvidingBundleFile.getResourceURL(TransformedManifestProvidingBundleFileWrapper.java:230)
        at org.eclipse.osgi.baseadaptor.bundlefile.BundleFileWrapperChain.getResourceURL(BundleFileWrapperChain.java:64)
        at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findResourceImpl(ClasspathManager.java:347)
        at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalResources(ClasspathManager.java:325)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalResources(DefaultClassLoader.java:207)
        at org.eclipse.osgi.internal.loader.BundleLoader.findLocalResources(BundleLoader.java:757)
        at org.eclipse.osgi.internal.loader.BundleLoader.findResources(BundleLoader.java:680)
        at org.eclipse.osgi.internal.loader.BundleLoader.getResources(BundleLoader.java:721)
        at org.eclipse.osgi.framework.internal.core.BundleHost.getResources(BundleHost.java:286)
        .......

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 leFileWrapperFactoryHook.java 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/ExtendedBundleFileWrapperFactoryHook.java b/org
index 04af22b..0b88279 100644
--- a/org.eclipse.virgo.osgi.extensions.equinox/src/main/java/org/eclipse/virgo/osgi/extensions/equinox/hooks/ExtendedBundleFileWrapperFactoryHook.java
+++ b/org.eclipse.virgo.osgi.extensions.equinox/src/main/java/org/eclipse/virgo/osgi/extensions/equinox/hooks/ExtendedBundleFileWrapperFactoryHook.java
@@ -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.


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


Current Time: Wed Apr 24 18:18:47 GMT 2024

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

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

Back to the top