Skip to content

Commit d985f93

Browse files
[FIX] XQuery, Java bindings: Catch linkage errors
1 parent a7901b9 commit d985f93

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

basex-core/src/main/java/org/basex/query/func/java/DynJavaFunc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public boolean init(final boolean enforce) throws QueryException {
6969
}
7070

7171
// method candidates
72-
final HashMap<String, ArrayList<Method>> allMethods = methods(clazz);
72+
final HashMap<String, ArrayList<Method>> allMethods = methods(clazz, info);
7373
methods = candidates(allMethods, name, types, arity, arities, false);
7474

7575
if(field != null || !methods.isEmpty()) return true;

basex-core/src/main/java/org/basex/query/func/java/JavaCall.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ private static Method moduleMethod(final Object module, final String name, final
426426

427427
// find method with identical name and arity
428428
final IntList arities = new IntList();
429-
final HashMap<String, ArrayList<Method>> allMethods = methods(module.getClass());
429+
final HashMap<String, ArrayList<Method>> allMethods = methods(module.getClass(), info);
430430
final ArrayList<Method> candidates = candidates(allMethods, name, types, arity, arities, true);
431431
final int cs = candidates.size();
432432
if(cs == 0) {
@@ -475,23 +475,31 @@ static QueryException noMember(final String name, final String[] types, final in
475475
/**
476476
* Returns a map with all relevant methods for a class.
477477
* @param clazz class
478+
* @param info input info (can be {@code null})
478479
* @return methods
480+
* @throws QueryException query exception
479481
*/
480-
static HashMap<String, ArrayList<Method>> methods(final Class<?> clazz) {
482+
static HashMap<String, ArrayList<Method>> methods(final Class<?> clazz, final InputInfo info)
483+
throws QueryException {
481484
final HashSet<String> names = new HashSet<>();
482485
final HashMap<String, ArrayList<Method>> list = new HashMap<>();
483-
for(final boolean bridge : new boolean[] { false, true }) {
484-
for(final Method method : clazz.getMethods()) {
485-
if(bridge == method.isBridge()) {
486-
final StringBuilder id = new StringBuilder().append(method.getName()).append('-');
487-
for(final Class<?> type : method.getParameterTypes()) {
488-
id.append(type.getName()).append('-');
489-
}
490-
if(names.add(id.toString())) {
491-
list.computeIfAbsent(method.getName(), n -> new ArrayList<>(1)).add(method);
486+
try {
487+
for(final boolean bridge : new boolean[] { false, true }) {
488+
for(final Method method : clazz.getMethods()) {
489+
if(bridge == method.isBridge()) {
490+
final StringBuilder id = new StringBuilder().append(method.getName()).append('-');
491+
for(final Class<?> type : method.getParameterTypes()) {
492+
id.append(type.getName()).append('-');
493+
}
494+
if(names.add(id.toString())) {
495+
list.computeIfAbsent(method.getName(), n -> new ArrayList<>(1)).add(method);
496+
}
492497
}
493498
}
494499
}
500+
} catch(final LinkageError err) {
501+
// referenced class could not be linked (e.g. temporarily unavailable during a rebuild)
502+
throw JAVAINIT_X_X.get(info, Util.className(err), err);
495503
}
496504
return list;
497505
}

0 commit comments

Comments
 (0)