Details
-
New Feature
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
Version 5.0.3
-
None
-
None
Description
The project https://github.com/centic9/poi-on-android allows to run Apache POI as part of Android Apps and thus also uses XMLBeans.
When trying to update to Apache POI 5.2.2 and XMLBeans 5.1.0, I saw that there is a problem with the Class-loading.
XMLBeans tries to do the following
cl.getResource("xyz.class")
However on Android you cannot get class-resources this way.
It seems this is only done to prevent a ClassNotFoundException in the call to Class.forName which follows.
Therefore I propose to change the code as follows so that we simply expect a ClassNotFoundException instead of doing this separate lookup via getResource()
// BEGIN CHANGES ========================================================================= // // Simply remove this pre-check and handle ClassNotFoundException below // as Android does not find .class-files in getResource() // // See https://stackoverflow.com/questions/72616517/looking-up-class-files-via-classloader-getresource-on-android // for a related question // /*if (cl.getResource(clName.replace(".", "/") + ".class") == null) { // if the first class isn't found in the package, continue with the next package break; }*/ try { @SuppressWarnings("unchecked") Class<? extends SchemaTypeLoader> cls = (Class<? extends SchemaTypeLoader>) Class.forName(clName, true, cl); list.add((SchemaTypeLoader) cls.getDeclaredField("typeSystem").get(null)); } catch (ClassNotFoundException e) { // if the first class isn't found in the package, continue with the next package // this can happen and thus is ignored here } catch (Exception e) { throw new XmlRuntimeException(e); } // END-CHANGES =========================================================================
Applying this change locally makes the project work on Android with Apache POI 5.2.2 and XMLBeans 5.1.0.
Attachments
Issue Links
- is a clone of
-
XMLBEANS-597 Improve support for using XMLBeans on Android
- Resolved