Files
openide/plugins/lombok/testData/highlighting/GetterLazyInvocationProduceNPE.java
Michail Plushnikov 4222be044e [lombok] IDEA-255688 Using existing functionality to skip checking expressions from field initializer
and to skip checking field initializer expression

GitOrigin-RevId: 67211ecbad65889dabe6385678cc1b7c47a96deb
2023-12-06 20:52:19 +00:00

38 lines
1.2 KiB
Java

import lombok.Getter;
public class GetterLazyInvocationProduceNPE {
private static class Bar {
public String sayHello() {
return "Bar{}";
}
}
private static class Car {
public String sayHello() {
return "Car{}";
}
}
private Bar <warning descr="Field 'bar' may be 'final'">bar</warning>;
private Bar <warning descr="Private field 'bar2' is never assigned">bar2</warning>;
private Car car;
public GetterLazyInvocationProduceNPE(Bar bar, Car car) {
this.bar = bar;
this.car = car;
}
// without warning, because of lazy getter and initialized in constructor
@Getter(lazy = true)
private final String barString = bar.sayHello();
// with warning, because of lazy getter and NOT initialized in constructor
@Getter(lazy = true)
private final String bar2String = bar2.<warning descr="Method invocation 'sayHello' will produce 'NullPointerException'">sayHello</warning>();
//with warning, because of NOT lazy getter
@Getter
private final String carString = car.<warning descr="Method invocation 'sayHello' will produce 'NullPointerException'">sayHello</warning>();
}