Community
Participate
Working Groups
Build Identifier: Just look at the attached example. Because one Foo instance doesn't have any children (= null) the call of the size method on the flattened list leads to a NullPointerException. In 2.0.1 this code returned "SIZE: 2". Looks like the null-valued properties are not ignored by the flatten method anymore. Reproducible: Always Steps to Reproduce: 1. Use the attached Xtend class 2. Run as Java Application
Created attachment 208308 [details] Xtend class
Works as defined: /** * [..] * The methods of the returned iterable may throw {@code NullPointerException} if any of the input iterators are null. * [..] */ public static final <T> Iterable<T> flatten(Iterable<? extends Iterable<? extends T>> inputs) { return Iterables.concat(inputs); }
Btw: The NPE was thrown with 2.0.1, too.
package org.xtext.example.mydsl import java.util.ArrayList import java.util.List class Sample { List<Sample> children def test() { val parents = new ArrayList<Sample>() val parent1 = new Sample() parent1.children = newArrayList(new Sample(), new Sample()) parents += new Sample() val allChildren = parents.map(parent | parent.children).flatten val size = allChildren.size println("Size: " + size) } } package org.xtext.example.mydsl; public class Main { public static void main(String[] args) { new Sample().test(); } } Exception in thread "main" java.lang.NullPointerException at com.google.common.collect.Iterables$3.apply(Iterables.java:422) at com.google.common.collect.Iterables$3.apply(Iterables.java:420) at com.google.common.collect.Iterators$8.next(Iterators.java:697) at com.google.common.collect.Iterators$5.hasNext(Iterators.java:505) at com.google.common.collect.Iterators.size(Iterators.java:122) at com.google.common.collect.Iterables.size(Iterables.java:73) at org.eclipse.xtext.xbase.lib.IterableExtensions.size(IterableExtensions.java:473) at org.xtext.example.mydsl.Sample.test(Sample.java:39)
Sorry, I have to admit I didn't execute this test case with 2.0.1 as I don't have such an environment available at the moment. I just know that I didn't get this NullPointerException before updating from 2.0.1 to 2.2.. Obviously the flatten implementation has not changed but the way the Iterable is filled... anyway I have to do some further investigations why there are null values in 2.2.