You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by "Richard Eckart de Castilho (Jira)" <de...@uima.apache.org> on 2020/10/15 18:08:00 UTC
[jira] [Comment Edited] (UIMA-6274) Creating a mock (or a proxy)
for Unittest of a JCas causes failure on further regular JCas
[ https://issues.apache.org/jira/browse/UIMA-6274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17214887#comment-17214887 ]
Richard Eckart de Castilho edited comment on UIMA-6274 at 10/15/20, 6:07 PM:
-----------------------------------------------------------------------------
It also works if one simply calls {{new TypeSystemImpl();}} before creating the proxy.
{code}
new TypeSystemImpl();
Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { JCas.class },
new InvocationHandler() {
@Override
public Object invoke(Object aProxy, Method aMethod, Object[] aArgs) throws Throwable {
return null;
}
});
JCas jCas1 = CasCreationUtils.createCas((TypeSystemDescription) null, null, null).getJCas();
jCas1.setDocumentText("test text");
{code}
was (Author: rec):
It also works if one simply calls {{new TypeSystemImpl();}} before creating the proxy.
{{noformat}}
new TypeSystemImpl();
Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { JCas.class },
new InvocationHandler() {
@Override
public Object invoke(Object aProxy, Method aMethod, Object[] aArgs) throws Throwable {
return null;
}
});
JCas jCas1 = CasCreationUtils.createCas((TypeSystemDescription) null, null, null).getJCas();
jCas1.setDocumentText("test text");
{{noformat}}
> Creating a mock (or a proxy) for Unittest of a JCas causes failure on further regular JCas
> -------------------------------------------------------------------------------------------
>
> Key: UIMA-6274
> URL: https://issues.apache.org/jira/browse/UIMA-6274
> Project: UIMA
> Issue Type: Bug
> Components: uimaj
> Affects Versions: 3.1.1SDK
> Environment: java 1.8.0-201
> Reporter: Serge Démoulin
> Priority: Major
> Attachments: easymock-green.zip, easymock-red.zip, exception.txt, proxy-green.zip, proxy-red.zip
>
>
> The following Code (see attached proxy-red.zip)
> {code:java}
> ProxyFactory f = new ProxyFactory();
> f.setTargetClass(JCas.class);
> f.getProxy();
> JCas jCas1 = JCasFactory.createJCas(new String[] {});
> jCas1.setDocumentText("test text"); // ==> ArrayIndexOutOfBoundsException
> {code}
> is throwing the following exception (see attached exception.txt)
> java.lang.ArrayIndexOutOfBoundsException: -1
> at ....FeatureStructureImplC._setIntValueCommon(FeatureStructureImplC.java:1636)
> WORKAROUND (see attached proxy-green.zip)
> Creating a regular JCas before fix the problem (without using the created JCas)
> {code:java}
> JCasFactory.createJCas(new String[] {});
> ProxyFactory f = new ProxyFactory();
> f.setTargetClass(JCas.class);
> f.getProxy();
> JCas jCas1 = JCasFactory.createJCas(new String[] {});
> jCas1.setDocumentText("test text"); // ==> No exception
> {code}
>
> EASYMOCK
> The same problem occurs with EasyMock (see attached easymock.-red.zip and easymock-green.zip)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)