Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[gemini-dev] [Gemini JPA] Patch for NPE in BundleArchive.getEntries(BundleArchive.java:71)

Dear Gemini JPA maintainers,

When using Gemini JPA outside of eclipse, the BundleArchive class fires a NullPointerException :

Caused by: java.lang.NullPointerException
    at org.eclipse.gemini.jpa.eclipselink.BundleArchive.getEntries(BundleArchive.java:71)
    at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.getClassNamesFromURL(PersistenceUnitProcessor.java:434)
    at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.buildClassSet(PersistenceUnitProcessor.java:118)
    at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:90)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:96)


Besides the lack of null check at line 71, this bug can be fixed by changing the call to findEntries line 67  :

- bundle.findEntries(".","*.class", true);
+ bundle.findEntries("/","*.class", true);

This seems to me that "/" actually makes more sense here, as we look for all classes in the bundle, and as I don't know how "." is interpreted here.

A patch, in which I also added a null check, is attached to this mail


Regards,

Matthieu Foucault


diff --git a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/eclipselink/BundleArchive.java b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/eclipselink/BundleArchive.java
index ef84e08..f4b9233 100644
--- a/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/eclipselink/BundleArchive.java
+++ b/org.eclipse.gemini.jpa/src/org/eclipse/gemini/jpa/eclipselink/BundleArchive.java
@@ -64,17 +64,19 @@ public class BundleArchive extends ArchiveBase implements Archive {
             entries = bundle.findEntries(binPath,"*.class", true);
             pathPrefixSize = binPath.length() + 2; // leading and trailing separator chars
         } else {
-            entries = bundle.findEntries(".","*.class", true);
+            entries = bundle.findEntries("/","*.class", true);
             pathPrefixSize = 3;
         }
         ArrayList<String> result = new ArrayList<String>();
-        while (entries.hasMoreElements()) {
-            URL bundleEntry = entries.nextElement();
-            try{
-                URI bundleUri = bundleEntry.toURI();
-                result.add(trimClassName(bundleUri.getPath()));
-            } catch (URISyntaxException e){
-                e.printStackTrace();
+        if (entries != null) {
+            while (entries.hasMoreElements()) {
+        	    URL bundleEntry = entries.nextElement();
+        	    try{
+                    URI bundleUri = bundleEntry.toURI();
+        	        result.add(trimClassName(bundleUri.getPath()));
+        	    } catch (URISyntaxException e){
+        		    e.printStackTrace();
+        	    }
             }
         }
         debugClassLoader("BundleArchive.getEntries() found entries: ",result);

Back to the top