compiler issue with after the recent changes in the compiler

Srikanth srikanth.adayapalam at oracle.com
Wed May 6 23:45:36 UTC 2020



On 07/05/20 2:26 am, Remi Forax wrote:
> Nope,
> the bug is in wrap(), using E instead of the diamond and javac compiles
>    public static <E> Array<E> wrap(E[] elements) {
>      return new Array<>(Objects.requireNonNull(elements));   // crash
>      return new Array<E>(Objects.requireNonNull(elements));  // compile
>    }

Hello Remi,

Can you try again ? This was an acknowledged problem as of 
https://github.com/openjdk/valhalla/pull/32 which subsequently got 
resolved through https://bugs.openjdk.java.net/browse/JDK-8244458 (which 
itself got subsumed and cumulatively fixed via JDK-8244414)

I am able to compile the file Array.java you have attached without a 
crash. I'll add it to javac's tests anyways in a future commit.

Thanks!
Srikanth
> Rémi
>
> ----- Mail original -----
>> De: "Remi Forax" <forax at univ-mlv.fr>
>> À: "Srikanth Adayapalam" <sadayapalam at openjdk.java.net>
>> Cc: "valhalla-dev" <valhalla-dev at openjdk.java.net>
>> Envoyé: Mercredi 6 Mai 2020 22:49:21
>> Objet: compiler issue with after the recent changes in the compiler
>> Hi Srikanth,
>> using a version compiled yesterday, javac struggle with my code :)
>> (i believe the issue is when compiling the method iterator() but i may be wrong)
>>
>> Also the "printing javac parameters" at the end looks like a debug knob not
>> being turn off.
>>
>> regards,
>> Rémi
>>
>> $ javac Array.java
>> java.lang.NullPointerException
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.code.Types$13.visitClassType(Types.java:2331)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.code.Types$13.visitClassType(Types.java:2318)
>> 	at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:1065)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4951)
>> 	at jdk.compiler/com.sun.tools.javac.code.Types.memberType(Types.java:2315)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:589)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1597)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Resolve.findDiamond(Resolve.java:2952)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Resolve$13.doLookup(Resolve.java:2898)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3367)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3617)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3602)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.comp.Resolve.resolveDiamond(Resolve.java:2894)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitNewClass(Attr.java:2728)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewClass.accept(JCTree.java:1827)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:689)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:2316)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1684)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:689)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:763)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:781)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1456)
>> 	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1044)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:689)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:763)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1239)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:890)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:689)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:763)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5308)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5190)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5112)
>> 	at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5057)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1348)
>> 	at
>> 	jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
>> 	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:316)
>> 	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
>> 	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
>> 	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
>> printing javac parameters to: /tmp/val-bug/javac.20200506_223738.args
>>
>>
>> ---
>>
>> import static java.util.stream.IntStream.range;
>>
>> import java.util.Arrays;
>> import java.util.Collection;
>> import java.util.Comparator;
>> import java.util.Iterator;
>> import java.util.List;
>> import java.util.ListIterator;
>> import java.util.NoSuchElementException;
>> import java.util.Objects;
>> import java.util.Spliterator;
>> import java.util.Spliterators;
>> import java.util.function.Consumer;
>> import java.util.function.Predicate;
>> import java.util.function.UnaryOperator;
>>
>> @__inline__
>> public final class Array<E> implements List<E> {
>>   private final E[] elements;
>>
>>   private Array(E[] elements) {
>>     this.elements = elements;
>>   }
>>
>>   public static <E> Array<E> wrap(E[] elements) {
>>     return new Array<>(Objects.requireNonNull(elements));
>>   }
>>
>>   @SafeVarargs
>>   public static <E> Array<E> of(E... elements) {
>>     return wrap(elements);
>>   }
>>
>>   public int length() {
>>     return elements.length;
>>   }
>>   
>>   @Override
>>   public boolean equals(Object obj) {
>>     if (obj instanceof Array) {
>>       var array = (Array<?>)obj;
>>       return Arrays.equals(elements, array.elements);
>>     }
>>     if (obj instanceof List) {
>>       return equalsList((List<?>)obj);
>>     }
>>     return false;
>>   }
>>   private boolean equalsList(List<?> list) {
>>     var it = list.iterator();
>>     for(var element: elements) {
>>       if (!it.hasNext()) {
>>         return false;
>>       }
>>       var other = it.next();
>>       if (!Objects.equals(element, other)) {
>>         return false;
>>       }
>>     }
>>     return !it.hasNext();
>>   }
>>   
>>   @Override
>>   public int hashCode() {
>>     return Arrays.hashCode(elements);
>>   }
>>   
>>   @Override
>>   public String toString() {
>>     return Arrays.toString(elements);
>>   }
>>
>>   @Override
>>   public int size() {
>>     return elements.length;
>>   }
>>
>>   @Override
>>   public boolean isEmpty() {
>>     return elements.length == 0;
>>   }
>>
>>   @Override
>>   public E get(int index) {
>>     return elements[index];
>>   }
>>   
>>   @Override
>>   public E set(int index, E element) {
>>     var old = elements[index];
>>     elements[index] = element;
>>     return old;
>>   }
>>   
>>   @Override
>>   public int indexOf(Object o) {
>>     var length = elements.length;
>>     return range(0, length).filter(i -> Objects.equals(o, elements[i])).findFirst()
>>         .orElse(-1);
>>   }
>>   
>>   @Override
>>   public int lastIndexOf(Object o) {
>>     for(var i = elements.length; --i >= 0;) {
>>       if (Objects.equals(o, elements[i])) {
>>         return i;
>>       }
>>     }
>>     return -1;
>>   }
>>
>>   @Override
>>   public boolean contains(Object o) {
>>     return Arrays.stream(elements).anyMatch(Predicate.isEqual(o));
>>   }
>>   
>>   @Override
>>   public boolean containsAll(Collection<?> collection) {
>>     return collection.stream().allMatch(this::contains);
>>   }
>>
>>   @Override
>>   public Iterator<E> iterator() {
>>     return new Iterator<>() {
>>       private int index;
>>       
>>       @Override
>>       public boolean hasNext() {
>>         return index < elements.length;
>>       }
>>       @Override
>>       public E next() {
>>         if (!hasNext()) {
>>           throw new NoSuchElementException("no such element");
>>         }
>>         return elements[index++];
>>       }
>>     };
>>   }
>>   
>>   @Override
>>   public ListIterator<E> listIterator() {
>>     return listIterator(0);
>>   }
>>   @Override
>>   public ListIterator<E> listIterator(int index) {
>>     return Arrays.asList(elements).listIterator(index);
>>   }
>>   @Override
>>   public List<E> subList(int fromIndex, int toIndex) {
>>     return Arrays.asList(elements).subList(fromIndex, toIndex);
>>   }
>>   
>>   @Override
>>   public Object[] toArray() {
>>     return Arrays.copyOf(elements, elements.length, Object[].class);
>>   }
>>
>>   @Override
>>   @SuppressWarnings("unchecked")
>>   public <T> T[] toArray(T[] a) {
>>     var elements = this.elements;
>>     var length = elements.length;
>>     if (a.length < length) {
>>       return (T[])Arrays.copyOf(elements, length, a.getClass());
>>     }
>>     System.arraycopy(elements, 0, a, 0, length);
>>     if (a.length > length) {
>>       a[length] = null;
>>     }
>>     return a;
>>   }
>>
>>   @Override
>>   public boolean add(E e) {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   @Override
>>   public void add(int index, E element) {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   @Override
>>   public boolean addAll(Collection<? extends E> c) {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   @Override
>>   public boolean addAll(int index, Collection<? extends E> c) {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   @Override
>>   public void clear() {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   @Override
>>   public E remove(int index) {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   @Override
>>   public boolean remove(Object o) {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   @Override
>>   public boolean removeAll(Collection<?> c) {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   @Override
>>   public boolean retainAll(Collection<?> c) {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   @Override
>>   public boolean removeIf(Predicate<? super E> filter) {
>>     throw new UnsupportedOperationException("operation not supported");
>>   }
>>   
>>   @Override
>>   public void forEach(Consumer<? super E> action) {
>>     for(var element: elements) {
>>       action.accept(element);
>>     }
>>   }
>>   
>>   @Override
>>   public void replaceAll(UnaryOperator<E> operator) {
>>     for(var i = 0; i < elements.length; i++) {
>>       elements[i] = operator.apply(elements[i]);
>>     }
>>   }
>>   
>>   @Override
>>   public void sort(Comparator<? super E> comparator) {
>>     Arrays.sort(elements, comparator);
>>   }
>>   
>>   @Override
>>   public Spliterator<E> spliterator() {
>>     return Spliterators.spliterator(elements, Spliterator.ORDERED);
>>   }
>> }



More information about the valhalla-dev mailing list