eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
157 stars 124 forks source link

eclipse can't build when error in switch #2870

Closed thomas2123 closed 1 week ago

thomas2123 commented 2 weeks ago

Hi, As I am a junior developper, I sometime make silly mistakes, sorry for that ^^'. As @stephan-herrmann suggested, I'll create a new issue for this one. I got this error in building with 2024-06 : image I tried to revert to 2024-03, but I got this error : 362346452-baa85cb4-d79a-44bb-bfc5-7bf2201e024c But when I reverted back to 2023-12, I did not have the error in building anymore. As I went through the error, I found that it was linked to this error : image It's a mistake I often make, to use an enum as a Constant in a switch.

When the enum is replaced by a Constant, the error goes away and the building works again. I hope I made this clear, sorry if I didn't. Good luck and thank you for the beautiful software you make.

thomas2123 commented 2 weeks ago

image proof I used eclipse 2024-06

srikanth-sankaran commented 2 weeks ago

Are you able to provide a small and self contained example to reproduce the problem ?? Screen shots are not very useful.

Can you try and attach a fuller stack trace when the problem shows up ?? Thanks.

stephan-herrmann commented 2 weeks ago

As I am a junior developper, I sometime make silly mistakes, sorry for that ^^'.

Every developer makes mistakes, and still the tool should not throw exceptions.

So, if you provide the code that triggered this as text, not picture, then your mistake will help us fix the tool for the benefit of others running into a similar mistake :)

thomas2123 commented 2 weeks ago

Thank you for your answers So here is a project that will trigger the building error : https://github.com/thomas2123/buildErrorProject And the stack trace ? : Internal compiler error: java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isRecord()" because "this.resolvedType" is null at org.eclipse.jdt.internal.compiler.ast.RecordPattern.resolveType(RecordPattern.java:119)

srikanth-sankaran commented 1 week ago

Reproduced. Thanks @thomas2123 for the test case.

srikanth-sankaran commented 1 week ago

Simplified test case:

public class X {

    enum EnumError {
        TEST(0);

        private int value;

        private EnumError(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    }

    public static void main(String[] args) {
        int bouh = 0;
        switch(bouh) {
        case EnumError.TEST.getValue() : 
            break;
        }
    }

}

JDK-22 reports:

X.java:20: error: cannot find symbol
        case EnumError.TEST.getValue() : 
                      ^
  symbol:   class TEST
  location: class EnumError
X.java:20: error: deconstruction patterns can only be applied to records, getValue is not a record
        case EnumError.TEST.getValue() : 
             ^
2 errors
thomas2123 commented 1 week ago

thanks for the fix ^^

srikanth-sankaran commented 1 week ago

The fix is not merged in - master is not open for development of 4.34 work. Reopening.

In any case, the ticket will be closed automatically when the fix is integrated.