Skip to content

Commit 6bc64ce

Browse files
authored
Merge pull request #842 from NativeScript/pete/improve-metadata
make metadata generator more robust
2 parents b8e0f1a + d9e81d7 commit 6bc64ce

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

android-metadata-generator/src/src/com/telerik/metadata/Builder.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ public static TreeNode build(String[] paths) throws Exception {
6060
// our class path API 17
6161
// Class<?> clazz = Class.forName(className, false, loader);
6262
ClassDescriptor clazz = ClassRepo.findClass(className);
63-
generate(clazz, root);
63+
if (clazz == null) {
64+
throw new ClassNotFoundException("Class " + className + " not found in the input android libraries.");
65+
} else {
66+
generate(clazz, root);
67+
}
6468
} catch (Throwable e) {
6569
System.out.println("Skip " + className);
6670
System.out.println("\tError: " + e.toString());
@@ -248,6 +252,12 @@ private static TreeNode getOrCreateNode(TreeNode root, TypeDescriptor type)
248252
} else {
249253
String name = ClassUtil.getCanonicalName(type.getSignature());
250254
ClassDescriptor clazz = ClassRepo.findClass(name);
255+
256+
// if clazz is not found in the ClassRepo, the method/field being analyzed will be skipped
257+
if (clazz == null) {
258+
return null;
259+
}
260+
251261
node = getOrCreateNode(root, clazz, null);
252262
}
253263

android-metadata-generator/src/src/com/telerik/metadata/ClassRepo.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ private ClassRepo() {
1212
private static ArrayList<ClassMapProvider> cachedProviders = new ArrayList<ClassMapProvider>();
1313

1414
public static void addToCache(ClassMapProvider classMapProvider) {
15-
for (String className : classMapProvider.getClassMap().keySet()) {
16-
for (ClassMapProvider cachedProvider : cachedProviders) {
17-
ClassDescriptor clazz = cachedProvider.getClassMap().get(className);
18-
if (clazz != null) {
19-
String errMsg = "Class " + className + " conflict: "
20-
+ classMapProvider.getPath() + " and " + cachedProvider.getPath();
21-
throw new IllegalArgumentException(errMsg);
22-
}
23-
}
24-
}
2515
cachedProviders.add(classMapProvider);
2616
}
2717

@@ -33,6 +23,7 @@ public static ClassDescriptor findClass(String className) {
3323
break;
3424
}
3525
}
26+
3627
return clazz;
3728
}
3829

android-metadata-generator/src/src/com/telerik/metadata/Generator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static void main(String[] args) throws Exception {
2929
"You need to pass an output directory!");
3030
}
3131

32-
if (args != null && args.length > 1) {
32+
if (args.length > 1) {
3333
params = new String[args.length - 1];
3434
for (int i = 1; i < args.length; i++) {
3535
params[i - 1] = args[i];

0 commit comments

Comments
 (0)