Skip to content

Commit

Permalink
Merge pull request #287 from apache/bugfix/285-NPE-while-deserializin…
Browse files Browse the repository at this point in the history
…g-an-XMI-in-a-PEAR-context

Issue #285: NPE while deserializing an XMI in a PEAR context
  • Loading branch information
reckart committed Jan 23, 2023
2 parents b3fcf24 + b5bf534 commit 8cea780
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,13 @@ void clearCasReset() {
id2fs.clear();

// pear caches
id2tramp = null;
id2base = null;
if (id2tramp != null) {
id2tramp.clear();
}
if (id2base != null) {
id2base.clear();
}

for (Iterator<Entry<ClassLoader, JCasHashMap>> it = cl2id2tramp.entrySet().iterator(); it
.hasNext();) {
Entry<ClassLoader, JCasHashMap> e = it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.apache.uima.UIMAFramework.getXMLParser;
import static org.apache.uima.util.CasCreationUtils.createCas;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -69,6 +70,28 @@ public void thatOneTrampolineIsUsedWhenClassLoaderIsSwitched() throws Exception,
.containsExactly(token).allMatch(t -> t.getClass().getClassLoader() == rootCl);
}

@Test
public void thatResettingCasInPearContextWorks() throws Exception, IOException {
ClassLoader rootCl = getClass().getClassLoader();

IsolatingClassloader clForToken = new IsolatingClassloader("Token", rootCl)
.redefining("org\\.apache\\.uima\\.cas\\.test\\.Token(_Type)?.*");

CASImpl casImpl = (CASImpl) createCas(loadTokensAndSentencesTS(), null, null, null);
casImpl.switchClassLoaderLockCasCL(new UIMAClassLoader(new URL[0], clForToken));
casImpl.setDocumentText("Test");

// The normal "reset" is blocked in PEAR mode, but e.g. the XmiCasDeserializerHandler calls
// resetNoQuestions()
casImpl.resetNoQuestions();

assertThatNoException().isThrownBy(() -> {
Type tokenType = casImpl.getTypeSystem().getType(Token.class.getName());
Annotation token = casImpl.createAnnotation(tokenType, 0, 1);
token.addToIndexes();
});
}

private TypeSystemDescription loadTokensAndSentencesTS() throws InvalidXMLException, IOException {
return getXMLParser().parseTypeSystemDescription(new XMLInputSource(
new File("src/test/resources/CASTests/desc/TokensAndSentencesTS.xml")));
Expand Down

0 comments on commit 8cea780

Please sign in to comment.