[concurrency-interest] ParallelArray classcastexception.

Doug Lea dl at cs.oswego.edu
Sun Mar 9 16:58:13 EDT 2008


Rune Schjellerup Philosof wrote:
> Hello all
> 
> How come this throws Exception in thread "Thread-5" 
> java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [[F
> 
>         Scan[] scans;
>         ForkJoinPool fjp = new ForkJoinPool();
>         ParallelArray<Scan> scanarray = 
> ParallelArray.createFromCopy(scans, fjp);
>         ParallelArray<float[]> tmp = scanarray.withMapping(new 
> Ops.Op<Scan, float[]>() {
>             @Override
>             public float[] op(Scan scan) {
>                 float[][] raw = scan.getSpectrum();
>                 return Spectrum.Resample(raw, _mzRange, 
> _resamplingFrequency);
>             }
>         }).all();

You should use the elementType version of "all" here. As in:
   .all(float[].class);
Otherwise the array is an Object array, where each of the
objects here is a float[]. Which is fine except for the Java casting
rules for arrays, which cause exception on your next line:

>         float[][] resampledSpectra = tmp.getArray();   <--- exception
> 

And actually, even this wasn't handled consistently, but now is
in updated jar.

-Doug



More information about the Concurrency-interest mailing list