[ https://issues.apache.org/jira/browse/XMLBEANS-612?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
PJ Fanning updated XMLBEANS-612: -------------------------------- Fix Version/s: Version 5.1.1 (was: Version 5.1.0) > Adjust Class loading to allow using XMLBeans on Android > ------------------------------------------------------- > > Key: XMLBEANS-612 > URL: https://issues.apache.org/jira/browse/XMLBEANS-612 > Project: XMLBeans > Issue Type: New Feature > Affects Versions: Version 5.0.3 > Reporter: Dominik Stadler > Assignee: Dominik Stadler > Priority: Major > Fix For: Version 5.1.1 > > > 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 > {noformat} > cl.getResource("xyz.class") {noformat} > 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() > {noformat} > // 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 > ========================================================================={noformat} > > Applying this change locally makes the project work on Android with Apache > POI 5.2.2 and XMLBeans 5.1.0. -- This message was sent by Atlassian Jira (v8.20.7#820007) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org