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 #590581] 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.ExtendedBund leFileWrapperFactoryHook$FileResourceEnforcingBundleFile.doe sJarEntryReallyExist(ExtendedBundleFileWrapperFactoryHook.ja va:183)
at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBund leFileWrapperFactoryHook$FileResourceEnforcingBundleFile.get LocalURLForEntry(ExtendedBundleFileWrapperFactoryHook.java:1 68)
at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBund leFileWrapperFactoryHook$FileResourceEnforcingBundleFile.doG etResourceURL(ExtendedBundleFileWrapperFactoryHook.java:154)
at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBund leFileWrapperFactoryHook$FileResourceEnforcingBundleFile.get ResourceURL(ExtendedBundleFileWrapperFactoryHook.java:148)
at org.eclipse.osgi.baseadaptor.bundlefile.BundleFileWrapperCha in.getResourceURL(BundleFileWrapperChain.java:64)
at org.eclipse.virgo.kernel.userregion.internal.equinox.Transfo rmedManifestProvidingBundleFileWrapper$TransformedManifestPr ovidingBundleFile.getResourceURL(TransformedManifestProvidin gBundleFileWrapper.java:230)
at org.eclipse.osgi.baseadaptor.bundlefile.BundleFileWrapperCha in.getResourceURL(BundleFileWrapperChain.java:64)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findRes ourceImpl(ClasspathManager.java:347)
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLoc alResources(ClasspathManager.java:325)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.fin dLocalResources(DefaultClassLoader.java:207)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalResou rces(BundleLoader.java:757)
at org.eclipse.osgi.internal.loader.BundleLoader.findResources( BundleLoader.java:680)
at org.eclipse.osgi.internal.loader.BundleLoader.getResources(B undleLoader.java:721)
at org.eclipse.osgi.framework.internal.core.BundleHost.getResou rces(BundleHost.java:286)
.......

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

Thank you!
Re: bundle.getResources("") throw NPE [message #590591 is a reply to message #590581] 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/or g/eclipse/virgo/osgi/extensions/equinox/hooks/ExtendedBundle FileWrapperFactoryHook.java b/org
index 04af22b..0b88279 100644
--- a/org.eclipse.virgo.osgi.extensions.equinox/src/main/java/or g/eclipse/virgo/osgi/extensions/equinox/hooks/ExtendedBundle FileWrapperFactoryHook.java
+++ b/org.eclipse.virgo.osgi.extensions.equinox/src/main/java/or g/eclipse/virgo/osgi/extensions/equinox/hooks/ExtendedBundle FileWrapperFactoryHook.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 #591365 is a reply to message #590591] 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 #591420 is a reply to message #590591] 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.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Previous Topic:bundle.getResources("") throw NPE
Next Topic:Virgo and JNDI Data Sources
Goto Forum:
  


Current Time: Fri Apr 19 05:36:17 GMT 2024

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

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

Back to the top