You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by GitBox <gi...@apache.org> on 2022/06/22 13:22:23 UTC

[GitHub] [felix-atomos] sten-navie opened a new issue, #60: ClassCastException when starting org.eclipse.equinox.metatype as a "Standard Bundle"

sten-navie opened a new issue, #60:
URL: https://github.com/apache/felix-atomos/issues/60

   During my experiments with Atomos I encountered the following issue.
   
   Having the following modules in a bootlayer:
   
   ```
   org.eclipse.osgi-3.17.200.jar
   org.apache.felix.atomos-1.0.0.jar	
   org.apache.felix.gogo.command-1.1.0.jar	
   org.apache.felix.gogo.runtime-1.1.2.jar	
   osgi.core-8.0.0-AtomosEquinox.jar
   org.osgi.service.metatype-1.4.1.jar
   org.osgi.service.cm-1.6.1.jar
   ```
   
   First I start the above modules by placing them into a folder named atomos-test and running:
   `java --add-modules=ALL-MODULE-PATH -p atomos-test -m org.apache.felix.atomos`
   
   If I now try to install and start equinox.metatype as a "Standard Bundle" via the gogo-shell, I get a ClassCastException:
   
   ```
   g! felix:install file:////PATH_TO_MY_FILES/org.eclipse.equinox.metatype-1.6.100.jar 
   Bundle ID: 42
   
   g! start 42
   java.lang.ClassCastException: class com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl cannot be cast to class javax.xml.parsers.SAXParserFactory (com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl is in module java.xml of loader 'bootstrap'; javax.xml.parsers.SAXParserFactory is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @162a66a1)
   ```
   
   - Tested with java 11 and 17.
   - If I place the equinox.metatype jar into the atomos-test folder and run it from the boot-layer, everything works.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [felix-atomos] tjwatson closed issue #60: ClassCastException when retrieving a SaxParserFactory service ref created by Equinox from a "Standard Bundle"

Posted by GitBox <gi...@apache.org>.
tjwatson closed issue #60: ClassCastException when retrieving a SaxParserFactory service ref created by Equinox from a "Standard Bundle"
URL: https://github.com/apache/felix-atomos/issues/60


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [felix-atomos] laeubi commented on issue #60: ClassCastException when retrieving a SaxParserFactory service ref created by Equinox from a "Standard Bundle"

Posted by GitBox <gi...@apache.org>.
laeubi commented on issue #60:
URL: https://github.com/apache/felix-atomos/issues/60#issuecomment-1164191408

   Do you use any startup options? Can you make sure that `osgi.compatibility.bootdelegation=false` is used?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [felix-atomos] sten-navie commented on issue #60: ClassCastException when retrieving a SaxParserFactory service ref created by Equinox from a "Standard Bundle"

Posted by GitBox <gi...@apache.org>.
sten-navie commented on issue #60:
URL: https://github.com/apache/felix-atomos/issues/60#issuecomment-1169949229

   I can confirm that applying PR  #61 fixes this problem for me. Many thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [felix-atomos] sten-navie commented on issue #60: ClassCastException when starting org.eclipse.equinox.metatype as a "Standard Bundle"

Posted by GitBox <gi...@apache.org>.
sten-navie commented on issue #60:
URL: https://github.com/apache/felix-atomos/issues/60#issuecomment-1163248236

   > > javax.xml.parsers.SAXParserFactory is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @162a66a1)
   > 
   > This indicates to me that you may have another "normal" bundle that is exporting `javax.xml.parsers` package also?
   
   This was my first thought, so I created a simple setup with just the jars listed above. There are no other "normal" bundles than the metatype one.  Running `which 42 javax.xml.parsers.SAXParserFactory`(where 42 is the bundle id of the meta-type bundle gives me: 
   ```
   Loaded from: java.xml_11.0.14 [14]
   ```
   
   Interestingly enough  if I run `which 0 javax.xml.parsers.SAXParserFactory`, even though the the system bundle does not list a export for javax.xml.parsers, I get the response:
   ```
   Loaded from: boot class loader
   ```
   
   My understanding  of class loader delegation in equinox is very limited, but when running my "real" app in the debugger I observed the following:
   -  It seems that meta-type bundle  SAXParserFactory.class is in the "un-named" module and a has a EquinoxClassLoader. (Checked by putting a breakpoint where the metatype bundle activator starts tracking SaxParserFactories).
   -  The factory returned by equinox in org.eclipse.osgi.internal.framework.XMLParsingServiceFactory uses a SAXParserFactory.class from the "javax.xml" module and null class loader. (Checked by breaking in XMLParsingServiceFactory.createService and stepping into SaxParserFactory.newInstance which specifies the class).
   
   best regards,
   
     Sten
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [felix-atomos] tjwatson commented on issue #60: ClassCastException when retrieving a SaxParserFactory service ref created by Equinox from a "Standard Bundle"

Posted by GitBox <gi...@apache.org>.
tjwatson commented on issue #60:
URL: https://github.com/apache/felix-atomos/issues/60#issuecomment-1164763512

   This is happening because `java.lang.Module.getClassLoader()` is returning null even though the javadoc says nothing about returning null.  It appears to return null for modules in the boot layer.  I guess that makes sense, but it means we need to handle the case for delegating to the boot layer modules for non java.* packages.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [felix-atomos] tjwatson commented on issue #60: ClassCastException when retrieving a SaxParserFactory service ref created by Equinox from a "Standard Bundle"

Posted by GitBox <gi...@apache.org>.
tjwatson commented on issue #60:
URL: https://github.com/apache/felix-atomos/issues/60#issuecomment-1170004149

   I went ahead and merged and opened an issue to add a testcase.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [felix-atomos] tjwatson commented on issue #60: ClassCastException when starting org.eclipse.equinox.metatype as a "Standard Bundle"

Posted by GitBox <gi...@apache.org>.
tjwatson commented on issue #60:
URL: https://github.com/apache/felix-atomos/issues/60#issuecomment-1163112489

   > javax.xml.parsers.SAXParserFactory is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @162a66a1)
   
   This indicates to me that you may have another "normal" bundle that is exporting `javax.xml.parsers` package also?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [felix-atomos] sten-navie commented on issue #60: ClassCastException when starting org.eclipse.equinox.metatype as a "Standard Bundle"

Posted by GitBox <gi...@apache.org>.
sten-navie commented on issue #60:
URL: https://github.com/apache/felix-atomos/issues/60#issuecomment-1164154832

   This does not seem to be related the equinox metatype implementation. I was able to repeat the same problem, by writing a simple Activator that just tracks javax.xml.parsers.SAXParserFactory. When receiving the reference I print out some info about the received class vs the wanted class and then try to cast the result, which again results in a ClassCastException:
   
   ```
   g! lb
   START LEVEL 1
      ID|State      |Level|Name
       0|Active     |    0|OSGi System Bundle (3.17.200.v20220215-2237)|3.17.200.v20220215-2237
       1|Active     |    1|java.base (11.0.14)|11.0.14
       2|Active     |    1|java.compiler (11.0.14)|11.0.14
       3|Active     |    1|java.datatransfer (11.0.14)|11.0.14
       4|Active     |    1|java.desktop (11.0.14)|11.0.14
       5|Active     |    1|java.logging (11.0.14)|11.0.14
       6|Active     |    1|java.management (11.0.14)|11.0.14
       7|Active     |    1|java.management.rmi (11.0.14)|11.0.14
       8|Active     |    1|java.naming (11.0.14)|11.0.14
       9|Active     |    1|java.prefs (11.0.14)|11.0.14
      10|Active     |    1|java.rmi (11.0.14)|11.0.14
      11|Active     |    1|java.security.jgss (11.0.14)|11.0.14
      12|Active     |    1|java.security.sasl (11.0.14)|11.0.14
      13|Active     |    1|java.smartcardio (11.0.14)|11.0.14
      14|Active     |    1|java.xml (11.0.14)|11.0.14
      15|Active     |    1|java.xml.crypto (11.0.14)|11.0.14
      16|Active     |    1|jdk.charsets (11.0.14)|11.0.14
      17|Active     |    1|jdk.compiler (11.0.14)|11.0.14
      18|Active     |    1|jdk.crypto.cryptoki (11.0.14)|11.0.14
      19|Active     |    1|jdk.crypto.ec (11.0.14)|11.0.14
      20|Active     |    1|jdk.internal.opt (11.0.14)|11.0.14
      21|Active     |    1|jdk.jartool (11.0.14)|11.0.14
      22|Active     |    1|jdk.javadoc (11.0.14)|11.0.14
      23|Active     |    1|jdk.jdeps (11.0.14)|11.0.14
      24|Active     |    1|jdk.jfr (11.0.14)|11.0.14
      25|Active     |    1|jdk.jlink (11.0.14)|11.0.14
      26|Active     |    1|jdk.localedata (11.0.14)|11.0.14
      27|Active     |    1|jdk.management (11.0.14)|11.0.14
      28|Active     |    1|jdk.management.jfr (11.0.14)|11.0.14
      29|Active     |    1|jdk.naming.dns (11.0.14)|11.0.14
      30|Active     |    1|jdk.naming.rmi (11.0.14)|11.0.14
      31|Active     |    1|jdk.security.auth (11.0.14)|11.0.14
      32|Active     |    1|jdk.security.jgss (11.0.14)|11.0.14
      33|Active     |    1|jdk.unsupported.desktop (11.0.14)|11.0.14
      34|Active     |    1|jdk.zipfs (11.0.14)|11.0.14
      35|Active     |    1|atomos (1.0.0)|1.0.0
      36|Active     |    1|Apache Felix Gogo Command (1.1.0)|1.1.0
      37|Active     |    1|Apache Felix Gogo Runtime (1.1.2)|1.1.2
      38|Active     |    1|Apache Felix Gogo Shell (1.1.2)|1.1.2
      39|Active     |    1|osgi.core (0.0.0)|0.0.0
   
   g! felix:install file:///<REDACTED-PATH>/tmp/atomos-test/atomos-saxparser-test-1.0.0-SNAPSHOT.jar 
   Bundle ID: 40
   g! felix:start 40
   Starting SAX Test
   Start tracking.
   Wanted class : javax.xml.parsers.SAXParserFactory Module = unnamed module @554f5786, Loader = org.eclipse.osgi.internal.loader.EquinoxClassLoader@2097740[java.xml:11.0.14(id=14)]
   Received impl class : com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl Module = module java.xml, Loader = null
   Super class : javax.xml.parsers.SAXParserFactory Module = module java.xml, Loader = null
   Super class : java.lang.Object Module = module java.base, Loader = null
   Trying to cast
   java.lang.ClassCastException: Cannot cast com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl to javax.xml.parsers.SAXParserFactory
   ```
   
   The relevant code (full code here https://gist.github.com/sten-navie/278b2efa077d170fb530083c0648b2dd):
   ```
           System.out.println("Starting SAX Test");
           Class<SAXParserFactory> wantedClass = SAXParserFactory.class;
   
          // use raw types, so that we do not immediately trigger a class-cast exception via an implicit cast
           serviceTracker = new ServiceTracker(bundleContext, wantedClass, new ServiceTrackerCustomizer() {
               @Override
               public Object addingService(ServiceReference serviceReference) {
                   Object s = bundleContext.getService(serviceReference);
                   if (s == null) {
                       System.out.println("Got null ref!!!");
                       return null;
                   }
                   Class<?> implcl = s.getClass();
                   printClass("Wanted class", wantedClass);
                   printClass("Received impl class", implcl);
                   Class<?> supercl = implcl.getSuperclass();
                   while (supercl != null) {
                       printClass("Super class", supercl);
                       supercl = supercl.getSuperclass();
                   }
   
                   // try to cast
                   System.out.println("Trying to cast");
                   SAXParserFactory f = wantedClass.cast(s);
                   System.out.println("Cast successful. Done!");
                   return f;
               }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [felix-atomos] sten-navie commented on issue #60: ClassCastException when retrieving a SaxParserFactory service ref created by Equinox from a "Standard Bundle"

Posted by GitBox <gi...@apache.org>.
sten-navie commented on issue #60:
URL: https://github.com/apache/felix-atomos/issues/60#issuecomment-1164287132

   > Do you use any startup options? Can you make sure that `osgi.compatibility.bootdelegation=false` is used?
   
   For my simple test I do not set any startup options. So it is whatever options Atomos.main sets. 
   
   I tried to add `osgi.compatibility.bootdelegation=false` but it does not change the result.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org