You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Kirk True <ki...@mustardgrain.com> on 2007/06/21 00:28:22 UTC
ArrayIndexOutOfBoundsException in CAS.getJCas
Hi all,
I'm getting an exception very infrequently when calling CAS.getJCas():
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at java.util.ArrayList.ensureCapacity(ArrayList.java:171)
at java.util.ArrayList.add(ArrayList.java:352)
at org.apache.uima.jcas.impl.JCasImpl.<init>(JCasImpl.java:531)
at org.apache.uima.jcas.impl.JCasImpl.getJCas(JCasImpl.java:498)
at org.apache.uima.cas.impl.CASImpl.getJCas(CASImpl.java:2460)
at com.mg.dgs.UimaPipeline.execute(UimaPipeline.java:88)
at com.mg.dgs.DpsWork.execute(DpsWork.java:29)
at com.mg.job.Task.execute(Task.java:103)
at com.mg.job.impl.local.LocalTaskEntry.execute(LocalTaskEntry.java:48)
at com.mg.job.impl.local.LocalComputeSpace$Worker.iteration(LocalComputeSpace.java:269)
at com.mg.util.DaemonRunnable.run(DaemonRunnable.java:92)
at java.lang.Thread.run(Thread.java:595)
I looked into it a little, and it looks like it could be a race condition. I am running a handful
of threads through this code "simultaneously", so it's likely.
The JCasImpl class contains a static Collection variable (builtInsWithNoJCas) which is checked and
-- if empty -- initialized. So my assumption is that this is a lazy instantion by the first
instance in its initializer block. It's possible for two very closely created JCasImpl instances
to both pass the check (builtInsWithNoJCas.size() == 0) and both try to populate the list.
ensureCapacity (in ArrayList) has a couple of checks that could potentially lead to a race
condition. This is all just guessing, however.
Is there any reason that the check for an empty builtInsWithNoJCas can't be in a synchronized
block or instantiated in a static block.
Thanks,
Kirk
Re: ArrayIndexOutOfBoundsException in CAS.getJCas
Posted by Marshall Schor <ms...@schor.com>.
Good catch, Kirk - this looks like a bug. I'll put in a Jira issue for
it and fix it - I think by making it a static initialization.
-Marshall
Kirk True wrote:
> Hi all,
>
> I'm getting an exception very infrequently when calling CAS.getJCas():
>
> java.lang.ArrayIndexOutOfBoundsException
> at java.lang.System.arraycopy(Native Method)
> at java.util.ArrayList.ensureCapacity(ArrayList.java:171)
> at java.util.ArrayList.add(ArrayList.java:352)
> at org.apache.uima.jcas.impl.JCasImpl.<init>(JCasImpl.java:531)
> at org.apache.uima.jcas.impl.JCasImpl.getJCas(JCasImpl.java:498)
> at org.apache.uima.cas.impl.CASImpl.getJCas(CASImpl.java:2460)
> at com.mg.dgs.UimaPipeline.execute(UimaPipeline.java:88)
> at com.mg.dgs.DpsWork.execute(DpsWork.java:29)
> at com.mg.job.Task.execute(Task.java:103)
> at com.mg.job.impl.local.LocalTaskEntry.execute(LocalTaskEntry.java:48)
> at com.mg.job.impl.local.LocalComputeSpace$Worker.iteration(LocalComputeSpace.java:269)
> at com.mg.util.DaemonRunnable.run(DaemonRunnable.java:92)
> at java.lang.Thread.run(Thread.java:595)
>
> I looked into it a little, and it looks like it could be a race condition. I am running a handful
> of threads through this code "simultaneously", so it's likely.
>
> The JCasImpl class contains a static Collection variable (builtInsWithNoJCas) which is checked and
> -- if empty -- initialized. So my assumption is that this is a lazy instantion by the first
> instance in its initializer block. It's possible for two very closely created JCasImpl instances
> to both pass the check (builtInsWithNoJCas.size() == 0) and both try to populate the list.
> ensureCapacity (in ArrayList) has a couple of checks that could potentially lead to a race
> condition. This is all just guessing, however.
>
> Is there any reason that the check for an empty builtInsWithNoJCas can't be in a synchronized
> block or instantiated in a static block.
>
> Thanks,
> Kirk
>
>
>