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

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 :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( 68)
at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBund leFileWrapperFactoryHook$FileResourceEnforcingBundleFile.doG etResourceURL(
at org.eclipse.virgo.osgi.extensions.equinox.hooks.ExtendedBund leFileWrapperFactoryHook$FileResourceEnforcingBundleFile.get ResourceURL(
at org.eclipse.osgi.baseadaptor.bundlefile.BundleFileWrapperCha in.getResourceURL(
at org.eclipse.virgo.kernel.userregion.internal.equinox.Transfo rmedManifestProvidingBundleFileWrapper$TransformedManifestPr ovidingBundleFile.getResourceURL(TransformedManifestProvidin
at org.eclipse.osgi.baseadaptor.bundlefile.BundleFileWrapperCha in.getResourceURL(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findRes ourceImpl(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLoc alResources(
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.fin dLocalResources(
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalResou rces(
at org.eclipse.osgi.internal.loader.BundleLoader.findResources(
at org.eclipse.osgi.internal.loader.BundleLoader.getResources(B
at org.eclipse.osgi.framework.internal.core.BundleHost.getResou rces(

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 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 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
+++ b/org.eclipse.virgo.osgi.extensions.equinox/src/main/java/or g/eclipse/virgo/osgi/extensions/equinox/hooks/ExtendedBundle
@@ -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 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: Tue Oct 25 07:01:09 GMT 2016

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

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