You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2020/10/01 19:28:18 UTC
[uima-uimaj] branch
UIMA-6243-JCas-returns-Annotation-when-asked-for-a-specific-subtype
updated: [UIMA-6243] JCas returns Annotation when asked for a specific
subtype
This is an automated email from the ASF dual-hosted git repository.
rec pushed a commit to branch UIMA-6243-JCas-returns-Annotation-when-asked-for-a-specific-subtype
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
The following commit(s) were added to refs/heads/UIMA-6243-JCas-returns-Annotation-when-asked-for-a-specific-subtype by this push:
new 5017fc7 [UIMA-6243] JCas returns Annotation when asked for a specific subtype
5017fc7 is described below
commit 5017fc7789fa8f2afb6ff355c35f217e4de1852e
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Thu Oct 1 21:28:09 2020 +0200
[UIMA-6243] JCas returns Annotation when asked for a specific subtype
- Added additional unit test with scenario that types are loaded via an extra classpath provided to the resource manager (previous test was only using an extra classloader provided to the resource manager)
- Update commons-io test dependency
- Fix the case where overwritten types are loaded through a classloader passed to the resource manager
- Adjusted unit test for the way UIMAv3 generates JCas wrappers (i.e. without the _Type and _Type$1 class files)
---
uimaj-core/pom.xml | 8 ++++----
.../org/apache/uima/cas/impl/FSClassRegistry.java | 19 ++++++++++---------
.../java/org/apache/uima/cas/impl/TypeSystemImpl.java | 10 +++++++---
.../org/apache/uima/cas/test/JCasClassLoaderTest.java | 6 ------
4 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/uimaj-core/pom.xml b/uimaj-core/pom.xml
index fe2959b..3f88dfe 100644
--- a/uimaj-core/pom.xml
+++ b/uimaj-core/pom.xml
@@ -145,10 +145,10 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.7</version>
- <scope>test</scope>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.7</version>
+ <scope>test</scope>
</dependency>
<!-- Uncomment one of these to add Saxon8 or 9 to the classpath for JUnit tests.
diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
index 99bcb34..d4cc147 100644
--- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
+++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
@@ -239,8 +239,9 @@ public abstract class FSClassRegistry { // abstract to prevent instantiating; th
return !jcasClass.getCanonicalName().equals(jcasClassName);
}
- boolean isPearOverride(ClassLoader cl) {
- return jcasClass.getClassLoader().equals(cl);
+ boolean isPearOverride(TypeSystemImpl tsi) {
+ JCasClassInfo baseJcci = tsi.getJcci(jcasClass.getName());
+ return baseJcci == null || !jcasClass.getClassLoader().equals(baseJcci.jcasClass.getClassLoader());
}
TypeImpl getUimaType(TypeSystemImpl tsi) {
@@ -1326,7 +1327,7 @@ public abstract class FSClassRegistry { // abstract to prevent instantiating; th
// cannot iterate over type2jcci - that map only has types with found JCas classes
- getGeneratorsForTypeAndSubtypes(tsi.topType, type2jcci, isPear, cl, r);
+ getGeneratorsForTypeAndSubtypes(tsi.topType, type2jcci, isPear, cl, r, tsi);
// for (Entry<String, JCasClassInfo> e : type2jcci.entrySet()) {
// TypeImpl ti = tsi.getType(Misc.javaClassName2UimaTypeName(e.getKey()));
@@ -1347,11 +1348,11 @@ public abstract class FSClassRegistry { // abstract to prevent instantiating; th
private static void getGeneratorsForTypeAndSubtypes(
TypeImpl ti,
- Map<String,
- JCasClassInfo> t2jcci,
+ Map<String, JCasClassInfo> t2jcci,
boolean isPear,
ClassLoader cl,
- FsGenerator3[] r) {
+ FsGenerator3[] r,
+ TypeSystemImpl tsi) {
TypeImpl jti = ti;
JCasClassInfo jcci = t2jcci.get(jti.getJCasClassName());
@@ -1362,13 +1363,13 @@ public abstract class FSClassRegistry { // abstract to prevent instantiating; th
// skip entering a generator in the result if
// in a pear setup, and this cl is not the cl that loaded the JCas class.
- // See method comment for why.
- if (!isPear || jcci.isPearOverride(cl)) {
+ // See method comment getGeneratorsForClassLoader(...) in for why.
+ if (!isPear || jcci.isPearOverride(tsi)) {
r[ti.getCode()] = (FsGenerator3) jcci.generator;
}
for (TypeImpl subtype : ti.getDirectSubtypes()) {
- getGeneratorsForTypeAndSubtypes(subtype, t2jcci, isPear, cl, r);
+ getGeneratorsForTypeAndSubtypes(subtype, t2jcci, isPear, cl, r, tsi);
}
}
diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java
index 03a7c47..c196793 100644
--- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java
+++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java
@@ -1500,7 +1500,7 @@ public class TypeSystemImpl implements TypeSystem, TypeSystemMgr, LowLevelTypeSy
// this includes any superClass of a jcas class which is not in this type system
if (! skip_loading_user_jcas) {
- JCasClassInfo jcci = getJcci(ti);
+ JCasClassInfo jcci = getOrCreateJcci(ti);
if (jcci != null) {
addJCasOffsetsWithSupers(jcci.jcasClass, tempIntFis, tempRefFis, tempNsr);
@@ -1615,7 +1615,7 @@ public class TypeSystemImpl implements TypeSystem, TypeSystemMgr, LowLevelTypeSy
List<FeatureImpl> tempRefFis,
List<FeatureImpl> tempNsrFis) {
- JCasClassInfo jcci = getJcci(ti);
+ JCasClassInfo jcci = getOrCreateJcci(ti);
if (null != jcci) { // could be null if class is not a JCas class
addJCasOffsets(jcci, tempIntFis, tempRefFis, tempNsrFis);
}
@@ -1693,10 +1693,14 @@ public class TypeSystemImpl implements TypeSystem, TypeSystemMgr, LowLevelTypeSy
}
}
- private JCasClassInfo getJcci(TypeImpl ti) {
+ private JCasClassInfo getOrCreateJcci(TypeImpl ti) {
return FSClassRegistry.getOrCreateJCasClassInfo(ti, cl_for_commit, type2jcci, lookup);
}
+ JCasClassInfo getJcci(String typeName) {
+ return type2jcci.get(typeName);
+ }
+
/**
* Feature "ids" - offsets without adjusting for whether or not they're in the class itself
* @param ti a type to compute these for
diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/test/JCasClassLoaderTest.java b/uimaj-core/src/test/java/org/apache/uima/cas/test/JCasClassLoaderTest.java
index 2fd8404..b192e44 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/test/JCasClassLoaderTest.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/test/JCasClassLoaderTest.java
@@ -116,12 +116,6 @@ public class JCasClassLoaderTest {
new File("target/test-classes/org/apache/uima/cas/test/Token.class"),
new File(cpPackageBase, "Token.class"));
FileUtils.copyFile(
- new File("target/test-classes/org/apache/uima/cas/test/Token_Type.class"),
- new File(cpPackageBase, "Token_Type.class"));
- FileUtils.copyFile(
- new File("target/test-classes/org/apache/uima/cas/test/Token_Type$1.class"),
- new File(cpPackageBase, "Token_Type$1.class"));
- FileUtils.copyFile(
new File("target/test-classes/org/apache/uima/cas/test/JCasClassLoaderTest$AddATokenAnnotator.class"),
new File(cpPackageBase, "JCasClassLoaderTest$AddATokenAnnotator.class"));
FileUtils.copyFile(