redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 429 forks source link

java.lang.ClassCastException: class org.eclipse.jdt.internal.compiler.lookup.ArrayBinding cannot be cast to class org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding #3700

Open callain-mirakl opened 2 months ago

callain-mirakl commented 2 months ago

The LSP cannot build my project anymore because of a ClassCastException. The class that causes the error is generated by jOOQ. It seems related to the version 1.32.0. I've rollbacked to 1.31.0 and it works

Environment
Steps To Reproduce
/*
 * This file is generated by jOOQ.
 */
package example.tables;

import example.JClassWithProblem;
import example.Keys;
import example.tables.records.JProblematicClassRecord;

import java.util.function.Function;

import javax.annotation.processing.Generated;

import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Function2;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Records;
import org.jooq.Row2;
import org.jooq.Schema;
import org.jooq.SelectField;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions;
import org.jooq.UniqueKey;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

/**
 * This class is generated by jOOQ.
 */
@Generated(
    value = {
        "https://www.jooq.org",
        "jOOQ version:3.18.17",
        "schema version:202406191130"
    },
    comments = "This class is generated by jOOQ"
)
@SuppressWarnings({ "all", "unchecked", "rawtypes", "this-escape" })
public class JProblematicClass extends TableImpl<JProblematicClassRecord> {

    private static final long serialVersionUID = 1L;

    public static final JProblematicClass TABLE_NAME = new JProblematicClass();

    /**
     * The class holding records for this type
     */
    @Override
    public Class<JProblematicClassRecord> getRecordType() {
        return JProblematicClassRecord.class;
    }

    /**
     * The column <code>schema_name.table_name.table_id</code>.
     */
    public final TableField<JProblematicClassRecord, String> TABLE_ID = createField(DSL.name("table_id"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column
     * <code>schema_name.table_name.foreign_ids</code>.
     */
    public final TableField<JProblematicClassRecord, String[]> FOREIGN_IDS = createField(DSL.name("foreign_ids"), SQLDataType.CLOB.nullable(false).defaultValue(DSL.field(DSL.raw("'{}'::text[]"), SQLDataType.CLOB)).array(), this, "");

    private JProblematicClass(Name alias, Table<JProblematicClassRecord> aliased) {
        this(alias, aliased, null);
    }

    private JProblematicClass(Name alias, Table<JProblematicClassRecord> aliased, Field<?>[] parameters) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table());
    }

    /**
     * Create an aliased <code>schema_name.table_name</code>
     * table reference
     */
    public JProblematicClass(String alias) {
        this(DSL.name(alias), TABLE_NAME);
    }

    /**
     * Create an aliased <code>schema_name.table_name</code>
     * table reference
     */
    public JProblematicClass(Name alias) {
        this(alias, TABLE_NAME);
    }

    /**
     * Create a <code>schema_name.table_name</code> table
     * reference
     */
    public JProblematicClass() {
        this(DSL.name("table_name"), null);
    }

    public <O extends Record> JProblematicClass(Table<O> child, ForeignKey<O, JProblematicClassRecord> key) {
        super(child, key, TABLE_NAME);
    }

    @Override
    public Schema getSchema() {
        return aliased() ? null : JClassWithProblem.SCHEMA_NAME;
    }

    @Override
    public UniqueKey<JProblematicClassRecord> getPrimaryKey() {
        return Keys.TABLE_NAME_PKEY;
    }

    @Override
    public JProblematicClass as(String alias) {
        return new JProblematicClass(DSL.name(alias), this);
    }

    @Override
    public JProblematicClass as(Name alias) {
        return new JProblematicClass(alias, this);
    }

    @Override
    public JProblematicClass as(Table<?> alias) {
        return new JProblematicClass(alias.getQualifiedName(), this);
    }

    /**
     * Rename this table
     */
    @Override
    public JProblematicClass rename(String name) {
        return new JProblematicClass(DSL.name(name), null);
    }

    /**
     * Rename this table
     */
    @Override
    public JProblematicClass rename(Name name) {
        return new JProblematicClass(name, null);
    }

    /**
     * Rename this table
     */
    @Override
    public JProblematicClass rename(Table<?> name) {
        return new JProblematicClass(name.getQualifiedName(), null);
    }

    // -------------------------------------------------------------------------
    // Row2 type methods
    // -------------------------------------------------------------------------

    @Override
    public Row2<String, String[]> fieldsRow() {
        return (Row2) super.fieldsRow();
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Function)}.
     */
    public <U> SelectField<U> mapping(Function2<? super String, ? super String[], ? extends U> from) {
        return convertFrom(Records.mapping(from));
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Class,
     * Function)}.
     */
    public <U> SelectField<U> mapping(Class<U> toType, Function2<? super String, ? super String[], ? extends U> from) {
        return convertFrom(toType, Records.mapping(from));
    }
}
Current Result
[Error - 16:30:33] 10 juil. 2024, 16:30:33 Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
Internal Error compiling /path/to/JProblematicClass.java
java.lang.RuntimeException: Internal Error compiling /Path/to/ProblematicClass.java
    at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:151)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassCastException: class org.eclipse.jdt.internal.compiler.lookup.ArrayBinding cannot be cast to class org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding (org.eclipse.jdt.internal.compiler.lookup.ArrayBinding and org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @272144f3)
    at org.eclipse.jdt.internal.compiler.lookup.CaptureBinding.downwardsProjection(CaptureBinding.java:547)
    at org.eclipse.jdt.internal.compiler.lookup.CaptureBinding.downwardsProjection(CaptureBinding.java:1)
    at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.upwardsProjection(ParameterizedTypeBinding.java:530)
    at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.upwardsProjection(ParameterizedTypeBinding.java:1)
    at org.eclipse.jdt.internal.compiler.lookup.TypeBinding.upwardsProjection(TypeBinding.java:325)
    at org.eclipse.jdt.internal.compiler.lookup.BoundSet.deriveTypeArgumentConstraints(BoundSet.java:974)
    at org.eclipse.jdt.internal.compiler.lookup.BoundSet.incorporate(BoundSet.java:630)
    at org.eclipse.jdt.internal.compiler.lookup.BoundSet.incorporate(BoundSet.java:511)
    at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.resolve(InferenceContext18.java:1215)
    at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.solve(InferenceContext18.java:1052)
    at org.eclipse.jdt.internal.compiler.lookup.InferenceContext18.solve(InferenceContext18.java:1035)
    at org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMethod18(ParameterizedGenericMethodBinding.java:256)
    at org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMethod(ParameterizedGenericMethodBinding.java:92)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:842)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:799)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod0(Scope.java:1753)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod(Scope.java:1655)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getMethod(Scope.java:3145)
    at org.eclipse.jdt.internal.compiler.ast.MessageSend.findMethodBinding(MessageSend.java:1138)
    at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:914)
    at org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:866)
    at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.resolve(ReturnStatement.java:362)
    at org.eclipse.jdt.internal.compiler.ast.Statement.resolveWithBindings(Statement.java:498)
    at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveStatements(ASTNode.java:725)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:713)
    at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:409)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:611)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1514)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1643)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:666)
    at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:904)
    at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:147)
Expected Result

Build completed with success (or equivalent log)

Additional Informations
alexcormier commented 1 month ago

We also ran into this; I submitted an issue to the compiler repo: eclipse-jdt/eclipse.jdt.core#2817.