Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8292756

java.lang.AssertionError at at jdk.compiler/com.sun.tools.javac.code.Scope$ScopeImpl.leave(Scope.java:386)

XMLWordPrintable

    • b17
    • generic
    • generic

        A DESCRIPTION OF THE PROBLEM :
        java.lang.AssertionError


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile the code below

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Should compile I think. It's hard to tell if there's an error or not though.
        ACTUAL -
        java.lang.AssertionError
        at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
        at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
        at jdk.compiler/com.sun.tools.javac.code.Scope$ScopeImpl.leave(Scope.java:386)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1465)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1082)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1253)
        at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:687)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:761)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5601)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5492)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5316)
        at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5255)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1317)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

        --release
        19
        --enable-preview
        /Users/jordanzimmerman/Downloads/test/Test.java


        ---------- BEGIN SOURCE ----------
        package test;

        import java.lang.reflect.*;
        import java.util.List;

        public class Test {
            public void test(List<Object> values, Class<?> collectionClass, Type componentType) {
                Class<?> primitiveClass = (componentType instanceof Class<?> clazz) && clazz.isPrimitive() ? clazz : null;
                Object tab = Array.newInstance(collectionClass, values.size());
                for (int i = 0; i < values.size(); ++i) {
                    Object value = values.get(i);
                    switch (value) {
                        case null -> Array.set(tab, i, value);
                        case Byte b when primitiveClass.equals(Byte.class) || primitiveClass.equals(byte.class) -> Array.setByte(tab, i, b);
                        case Short s when primitiveClass.equals(Short.class) || primitiveClass.equals(short.class) -> Array.setShort(tab, i, s);
                        case Character c when primitiveClass.equals(Character.class) || primitiveClass.equals(char.class) -> Array.setChar(tab, i, c);
                        case Integer v when primitiveClass.equals(Integer.class) || primitiveClass.equals(int.class) -> Array.setInt(tab, i, v);
                        case Long l when primitiveClass.equals(Long.class) || primitiveClass.equals(long.class) -> Array.setLong(tab, i, l);
                        case Float f when primitiveClass.equals(Float.class) || primitiveClass.equals(float.class) -> Array.setFloat(tab, i, f);
                        case Double d when primitiveClass.equals(Double.class) || primitiveClass.equals(double.class) -> Array.setDouble(tab, i, d);
                        default -> throw new RuntimeException(); // TODO
                    }
                }
            }
        }

        ---------- END SOURCE ----------

        FREQUENCY : always


              jlahoda Jan Lahoda
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: