Menu

Can't generate a stream for ArrayList

Anonymous
2016-03-17
2016-03-31
  • Anonymous

    Anonymous - 2016-03-17

    Hi.
    I'm trying to use streamsupport 1.4.2, but an error is occurred.
    I use RoboVM Studio for iOS development.

    Here is my code.


    ArrayList<Subscription> subscriptions = new ArrayList<>();
    // ...
    StreamSupport.stream(subscriptions).forEach(Subscription::unsubscribe);


    This causes an error.


    java.lang.Error: java.lang.NoSuchFieldException: elementData
    at java8.util.ArrayListSpliterator.<clinit>(ArrayListSpliterator.java:211)


     
  • Anonymous

    Anonymous - 2016-03-17

    I found a warning before the error.

    WARN java.lang.class: Class.forName() failed to load 'android.util.DisplayMetrics'. Use the -forcelinkclasses command line option or add <forceLinkClasses><pattern>android.util.DisplayMetrics</pattern></forceLinkClasses> to your robovm.xml file to link it in.

    But android.util.DisplayMetrics does not exist because I compile for iOS.

     
  • Stefan Zobel

    Stefan Zobel - 2016-03-17

    iOS is not supported, I'm sorry.

     
  • Stefan Zobel

    Stefan Zobel - 2016-03-17

    I'd try the following:

    System.setProperty("java8.util.Spliterators.assume.oracle.collections.impl", "false");
    

    This must be issued before anything from streamsupport is used / get's loaded - i.e., as early as possible (e.g., in your Main.java).

    Please keep me informed whether that works in your case.

     

    Last edit: Stefan Zobel 2016-03-17
  • Stefan Zobel

    Stefan Zobel - 2016-03-17

    It would be nice if you could test the "java8.util.Spliterators.assume.oracle.collections.impl" property approach first.

    If that works out, I can try to add RoboVM detection in a second step (I can make an interim test version for you).

    If that also works, I could add that as an "off the record" feature in the next release (1.4.3). But please note, that I'll never officially support RoboVM (let alone iOS) since I can only support platforms that I can test myself regularly.

    Btw., the warning regarding "android.util.DisplayMetrics" will appear in both scenarios (property and runtime detection) - just ignore it.

     
  • Anonymous

    Anonymous - 2016-03-18

    Thanks for your reply.

    "java8.util.Spliterators.assume.oracle.collections.impl" property approach worked.

    But please note, that I'll never officially support RoboVM (let alone iOS)

    Of course I get it. Because RoboVM compiles Java bytecode to native binaries. I think you are enough for Java bytecode level support.

     
  • Stefan Zobel

    Stefan Zobel - 2016-03-18

    OK, fine. Then let's go for the next round.

    The attached interim version attempts to do without the "assume.oracle.collections.impl" property by detecting RoboVM at runtime.

    Could you please test this version? Don't forget to remove the "assume.oracle.collections.impl" property. The test would be more meaningful if you could test with parallelStream() - ArrayList is ok as a collection to test.

    If the test works, I can add RoboVM detection in the 1.4.3 release if you want.

     
  • Anonymous

    Anonymous - 2016-03-30

    I'm sorry for the late reply.

    StreamSupport.stream(list).forEach(...) is OK. But StreamSupport.parallelStream(list).forEach(...) throws an Exception.

    java.lang.Error: java.lang.NoSuchFieldException: threadLocals
    at java8.util.concurrent.ForkJoinWorkerThread.<clinit>(ForkJoinWorkerThread.java:256)
    at java8.util.concurrent.ForkJoinPool$DefaultForkJoinWorkerThreadFactory.newThread(ForkJoinPool.java:636)
    at java8.util.concurrent.ForkJoinPool.createWorker(ForkJoinPool.java:1344)
    at java8.util.concurrent.ForkJoinPool.tryAddWorker(ForkJoinPool.java:1368)
    at java8.util.concurrent.ForkJoinPool.signalWork(ForkJoinPool.java:1494)
    at java8.util.concurrent.ForkJoinPool.externalPush(ForkJoinPool.java:1968)
    at java8.util.concurrent.ForkJoinTask.fork(ForkJoinTask.java:700)
    at java8.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:359)
    at java8.util.concurrent.CountedCompleter.exec(CountedCompleter.java:742)
    at java8.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:291)
    at java8.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:403)
    at java8.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:732)
    at java8.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:195)
    at java8.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:210)
    at java8.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:232)
    at java8.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:459)
    at java8.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:624)

     
  • Stefan Zobel

    Stefan Zobel - 2016-03-30

    Ah, ok. Thanks for testing.
    I'll fix this and come back to you with another interim version.

    Thanks,
    Stefan

     
  • Stefan Zobel

    Stefan Zobel - 2016-03-30

    Please find attached a fixed version. Could you please test again with this version and let me know your results?

    Thanks,
    Stefan

     
  • Anonymous

    Anonymous - 2016-03-31

    Both stream() and parallelStream() work.

    Thanks for your great job.

     
  • Stefan Zobel

    Stefan Zobel - 2016-03-31

    Good. Thanks for testing! So, I'll add this small enhancement to the 1.4.3 release.

    But please keep in mind that streamsupport on RoboVM is still not officially supported.

    If it works - fine, you are lucky. If not - too bad, but it's not my department :-)

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.