2

I have a superclass

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ErrorResponse {
    @JsonProperty
    private String message;
}

And I have a child one

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(builderMethodName = "_builder") // add custom builder name to avoid compilation issue 'return type is not compatible...'
@EqualsAndHashCode(callSuper=true)
public class AskQuestionErrorResponse extends ErrorResponse {
    @JsonProperty
    private String status;

    @Builder(builderMethodName = "_builder") // add custom builder name to avoid compilation issue 'return type is not compatible...'
    private AskQuestionErrorResponse(String status, String message){
        super(message);
        this.status = status;
    }
}

When I use a builder to create an object like this

AskQuestionErrorResponse._builder()
   .status(1)
   .message("my message here").build()

Intellij shows me message in red and there is an issue cannot resolve method 'message(java.lang.String)' Anyway project compiles and runs even with this error.

I've already enabled annotations precessing.

If I comment field from superclass like this

AskQuestionErrorResponse._builder()
                .status(ex.getStatus().getValue()
                //.message(ex.getMessage()
                ).build()

It works. It seems that it does not see superclass members. I've also tried maven clean and install, rebuild project.

UPDATE Lombok plugin is installed enter image description here

Annotation Processors are enabled in Preferences and in Default preferences

enter image description here

enter image description here

Vitalii
  • 10,091
  • 18
  • 83
  • 151

2 Answers2

0

I found it. If you take a look to my class you'll see two @Builder annotations. I removed first one and magic happens. Now my class looks like this and there is no warning

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper=true)
public class AskQuestionErrorResponse extends ErrorResponse {
    @JsonProperty
    private String status;

    @Builder(builderMethodName = "_builder") // add custom builder name to avoid compilation issue 'return type is not compatible...'
    public AskQuestionErrorResponse(String status, String message){
        super(message);
        this.status = status;
    }
}

Hope it helps :)

Vitalii
  • 10,091
  • 18
  • 83
  • 151
-1

You need to install the Intellij Lombok plugin so that it can understand the annotations before the compilation to byte code. https://projectlombok.org/setup/intellij

Mark
  • 2,260
  • 18
  • 27
  • It's already installed. `AskQuestionErrorResponse._builder().status(ex.getStatus().getValue()).build()` without field of superclass works perfectly – Vitalii Dec 14 '17 at 13:58
  • There is some additional information here which might help https://stackoverflow.com/questions/24006937/lombok-annotations-do-not-compile-under-intellij-idea?rq=1 – Mark Dec 14 '17 at 13:59
  • 1
    There does seem to be a problem with the @Builder annotation though. A possible (but not perfect) work around is discussed here https://reinhard.codes/2015/09/16/lomboks-builder-annotation-and-inheritance/ – Mark Dec 14 '17 at 14:04