projectlombok / lombok

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

StackOverflowError when using @Getter on static field of @ConfigurationProperties class #1190

Open gavvvr opened 8 years ago

gavvvr commented 8 years ago

Not sure if it is a bug of Spring boot annotation processor or lombok, anyways... I have the following class:

package com.myapp;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "myapp")
@Getter
@Setter
public class MyappProperties implements InitializingBean {
    private static MyappProperties instance;

    private String engineDir;

    @Override
    public void afterPropertiesSet() throws Exception {
        instance = this;
    }
}

It causes StackOverflowError on compilation with @ConfigurationProperties annotation present (without it, compilation is successful).

@ConfigurationProperties is processed by Spring boot annotation processor and probably causes some conflict. Error is caused by @Getter on static field. If i set @Getter only for engineDir property and leave @ConfigurationProperties, compilation is successful too.

Caused by: java.lang.StackOverflowError at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1955) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.asSuper(Types.java:1952) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1968) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1955) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.asSuper(Types.java:1952) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1975) at com.sun.tools.javac.code.Types$13.visitClassType(Types.java:1955) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.asSuper(Types.java:1952) at com.sun.tools.javac.code.Types$4.visitClassType(Types.java:921) at com.sun.tools.javac.code.Types$4.visitClassType(Types.java:844) at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:786) at com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4571) at com.sun.tools.javac.code.Types.isSubtype(Types.java:840) at com.sun.tools.javac.code.Types.isSubtype(Types.java:804) at com.sun.tools.javac.code.Types.isSubtypeUncheckedInternal(Types.java:757) at com.sun.tools.javac.code.Types.isSubtypeUnchecked(Types.java:741) at com.sun.tools.javac.code.Types.isConvertible(Types.java:299) at com.sun.tools.javac.code.Types.isAssignable(Types.java:2164) at com.sun.tools.javac.code.Types.isAssignable(Types.java:2125) at com.sun.tools.javac.model.JavacTypes.isAssignable(JavacTypes.java:104) at org.springframework.boot.configurationprocessor.TypeUtils.isCollectionOrMap(TypeUtils.java:108) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processSimpleLombokTypes(ConfigurationMetadataAnnotationProcessor.java:257) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processTypeElement(ConfigurationMetadataAnnotationProcessor.java:188) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processNestedType(ConfigurationMetadataAnnotationProcessor.java:321) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processNestedLombokTypes(ConfigurationMetadataAnnotationProcessor.java:290) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processTypeElement(ConfigurationMetadataAnnotationProcessor.java:190) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processNestedType(ConfigurationMetadataAnnotationProcessor.java:321) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processNestedLombokTypes(ConfigurationMetadataAnnotationProcessor.java:290) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processTypeElement(ConfigurationMetadataAnnotationProcessor.java:190) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processNestedType(ConfigurationMetadataAnnotationProcessor.java:321)

Processing of @ConfigurationProperties annotation is performed with org.springframework.boot:spring-boot-configuration-processor

Brandon0204 commented 7 years ago

prababely it is caused by InitializingBean but not the getter, may be you can have a try remove InitializingBean and keep getter

FancyBanana commented 5 years ago

Encountered simmilar problem when trying to implement singleton on @Configuration class with @Getter and @Setter. In my case the following code causes StackOverflowError during annotation resolution on everything that tries to parse the code (java language server silently stops working, maven throws StackOverflowError without details)

@Getter
@Setter
@Configuration
@ConfigurationProperties("app")
@Log4j
public class AppConfiguration {

    // some members ...

    // Adding this code will cause StackOverflow during resolution of annotations

    private static AppConfiguration instance;

    @Autowired
    private void setInstance(AppConfiguration appConfiguration) {
        AppConfiguration.instance = appConfiguration;
    }

    public static AppConfiguration getInstance() {
        return instance;
    }

}