Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #285: NPE while deserializing an XMI in a PEAR context #287

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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