Skip to content

Commit

Permalink
Merge pull request #396 from apache/bugfix/395-Potential-failure-to-l…
Browse files Browse the repository at this point in the history
…ook-up-UIMA-internal-classes-in-OSGI-like-contexts

Issue #395: Potential failure to look up UIMA-internal classes in OSGI-like contexts
  • Loading branch information
reckart authored Sep 30, 2024
2 parents 69ebb88 + 6d4567c commit 49d52e7
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import java.util.List;
import java.util.StringTokenizer;

import org.apache.uima.UIMAFramework;
import org.apache.uima.cas.impl.FSClassRegistry;
import org.apache.uima.cas.impl.FsGenerator3;
import org.apache.uima.cas.impl.TypeSystemImpl;

/**
Expand Down Expand Up @@ -248,11 +248,11 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
c = findClass(name);
}
} catch (ClassNotFoundException e) {
if (name.startsWith(FsGenerator3.class.getPackage().getName() + ".")) {
if (isUimaInternalPackage(name)) {
// There may be cases where the target class uses a classloader that has no access
// to the UIMA internal classes - in particular to the FSGenerator3 - so we force using
// the UIMA classloader in this case.
c = FsGenerator3.class.getClassLoader().loadClass(name);
c = UIMAFramework.class.getClassLoader().loadClass(name);
} else {
// delegate class loading for this class-name
c = super.loadClass(name, false);
Expand All @@ -268,6 +268,11 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
}
}

private boolean isUimaInternalPackage(String name) {
return name.startsWith("org.apache.uima.cas.impl.")
|| name.startsWith("org.apache.uima.jcas.cas.");
}

/*
* loads resource from this class loader first, if possible (non-Javadoc)
*
Expand Down

0 comments on commit 49d52e7

Please sign in to comment.