projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.82k stars 2.38k forks source link

[BUG] very strange, mvn compile failed at the line import X.Fields(generated by @FieldNameConstants) line #3561

Open magical-l opened 9 months ago

magical-l commented 9 months ago

Describe the bug mvn compile failed at the line import X.Fields(generated by @FieldNameConstants) line

To Reproduce

1, I have a class com.Ac, extends another class AirBeanBase from a 3rd lib, and they both @FieldNameConstants, like this:

package com;

import com.shuyun.air.framework.domain.AirBeanBase;
import lombok.experimental.FieldNameConstants;

@FieldNameConstants
public class Ac extends AirBeanBase {
    private int i;
}

and AirBeanBase:

package com.shuyun.air.framework.domain;
//......
import io.micronaut.core.annotation.Introspected;
import lombok.Data;
import lombok.experimental.FieldNameConstants;

@Introspected
@Data
@FieldNameConstants
abstract public class AirBeanBase implements AirBean {
//......

2, a test class, let's say Test, in same source root, calls the field i, like this:

package test;
import com.Ac.Fields;

public interface Test {
    public static void main(String[] args) {
        System.out.println(Fields.i);
    }
}

3, in the intellij editor, the codes are very ok, no compile error or red underline.

4, mvn clean compile, and it will fail at Test line 3, that's the import com.Ac.Fields; line, with message 导入需要com.shuyun.air.framework.domain.AirBeanBase.Fields的规范名称--it means 'Import the name of the specification that requires com.shuyun.air.framework.domain.AirBeanBase.Fields (instead of the com.Ac.Fields)', sorry but I don't know what's the exactly English version message. it looks like the Ac class has no Fields inner class.

5, I've tried many things as following, some can pass the compile and some can not. 5.0, remove all other fields and methods, so now it has only one field.

5.1, rename the field name, not ok, so now it's called i.

5.2, rename the Ac class 5.2.1, delete some parts of the raw class name. some shorter names ok while some are not. as you see, the Ac is one of the not ok class name, A is ok but B is not. 5.2.2, add a number after raw class name like 1,2 or 3. 1 and 2 are not ok , 3 some are ok but some are not, maybe depends on the former parts.

5.3, move to other package, almost not ok(but some are ok), so now it's in com package.

5.4, change the parent class 5.4.1, let Ac extends another class with @FieldNameConstants, it's ok... 5.4.2, copy AirBeanBase to other package, and let Ac extend the copy class, it's ok... even if keep the new package's full name not changing, all ok. that's why I have to keep the raw package name and raw class name here.

5.5, partly inline the import statement in Test class as

import com.Ac;
//......
public static void main(String[] args) {
        System.out.println(Ac.Fields.i);
    }

it worked! but that's not work:

import com.Ac;
import com.Ac.Fields;//not used import statement with grey color, will be remove if optimize imports. but mvn compile will fail while it stays here
//......
public static void main(String[] args) {
        System.out.println(Ac.Fields.i);
    }

5.6, outside of the code 5.6.1, disable-reenable the lombok plugin, not work. 5.6.2, intellij idea File | Invalidate Caches... not work. 5.6.3, File | Settings | Build, Execution, Deployment | Compiler | Annotation Processors, disable-reenable 'Enable annotation processing', not work.

Expected behavior I hope mvn compile result as I see in editor(no compile error).

Version info (please complete the following information):

java version:

java version "21" 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21+35-LTS-2513)
Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing)

** but the project uses 11.

intellij idea version:

IntelliJ IDEA 2023.1.4 (Ultimate Edition)
Build #IU-231.9225.16, built on July 12, 2023
Licensed to Hunan Institute of Science and Technology / tmu itmanager
Subscription is active until February 9, 2024.
Runtime version: 17.0.7+10-b829.16 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2014M
Cores: 16
Registry:
    debugger.new.tool.window.layout=true
    ide.experimental.ui=true

Non-Bundled Plugins:
    in.thekalinga.snippet.intellij (6.1.0)
    PsiViewer (231-SNAPSHOT)
    Statistic (4.2.7)
    com.codeium.intellij (1.2.44)
    String Manipulation (9.9.0)
    de.juserv.intellij-propertiessort (0.3)
    Key Promoter X (2023.1.0)
    org.jetbrains.kotlin (231-1.9.0-release-358-IJ8770.65)
    MavenRunHelper (4.23.222.2964.0)
    indent-rainbow.indent-rainbow (2.1.0)
    org.exbin.deltahex.intellij (0.2.8.1)
    org.sonarlint.idea (8.4.0.73538)
    org.intellij.gitee (2023.1.0)
    izhangzhihao.rainbow.brackets (2023.3.2)
    MetricsReloaded (1.12)
    LivePlugin (0.8.6 beta)
    mobi.hsz.idea.gitignore (4.5.1)

Kotlin: 231-1.9.0-release-358-IJ8770.65

idea lombok plugin version: bundled 231.9225.16

maven-compiler-plugin.version: 3.10.1 lombok version in pom: 1.18.30</lombok.version>

<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                                <version>${lombok.version}</version>
                            </path>

                            <path>
                                <groupId>io.micronaut</groupId>
                                <artifactId>micronaut-inject-java</artifactId>
                                <version>${micronaut.version}</version>
                            </path>
                            <path>
                                <groupId>io.micronaut</groupId>
                                <artifactId>micronaut-validation</artifactId>
                                <version>${micronaut.version}</version>
                            </path>
                            <path>
                                <groupId>io.micronaut</groupId>
                                <artifactId>micronaut-http-validation</artifactId>
                                <version>${micronaut.version}</version>
                            </path>
                            <path>
                                <groupId>io.micronaut.data</groupId>
                                <artifactId>micronaut-data-processor</artifactId>
                                <version>${micronaut.data.version}</version>
                            </path>
                            <path>
                                <groupId>io.micronaut.openapi</groupId>
                                <artifactId>micronaut-openapi</artifactId>
                                <version>${micronaut.openapi.version}</version>
                            </path>
                        </annotationProcessorPaths>
                    </configuration>
                </plugin>

** uses micronaut 3.10.1, not springboot

tDaem commented 2 weeks ago

I encountered the same problem, as long as it is a property constant generated by @ FieldNameConstant, it will encounter an error when compiling after referencing it