XMLBEANS-612: Adjust classloading for better Android support
Using Classloader.getResource() for .class-files fails on Android where
the special classloader does not return class-files as resources.
As this is only done as pre-check here if loading the class will work,
we can replace it with catching a ClassNotFoundException instead to
only use proper reflection functionality and thus make this
work on Android as well.
git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1901904 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java b/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
index 68b1581..f59e922 100644
--- a/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
+++ b/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
@@ -152,14 +152,13 @@
for (String prefix : basePackage) {
for (String holder : baseSchemas) {
String clName = prefix + ".system." + holder + ".TypeSystemHolder";
- 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 this 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);
}