Files
Tagir Valeevandintellij-monorepo-bot ff1cfed0de [java-dfa] Do not assume that fields are non-initialized in readResolve() when readObject() is present
Fixes IDEA-351947 False positive warning 'Nullability and data flow problems' in readResolve

GitOrigin-RevId: 26c71c3e26c087334741a5a098812f91144bdcd4
2024-04-17 14:20:27 +00:00

31 lines
900 B
Java

import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.Base64;
class Test implements Serializable {
@NotNull String string;
Test(@NotNull String string) {
this.string = string;
}
@Serial
private void readObject(ObjectInputStream in) throws IOException {
this.string = in.readUTF();
}
@Serial
protected Object readResolve() {
if (<warning descr="Condition 'string == null' is always 'false'">string == null</warning>) {
throw new IllegalStateException("Wrong object!");
}
return this;
}
public static void main(String[] args) throws IOException, ClassNotFoundException {
byte[] data = Base64.getDecoder().decode("rO0ABXNyAARUZXN0ST9d8XKvH/0CAAFMAAZzdHJpbmd0ABJMamF2YS9sYW5nL1N0cmluZzt4cHA=");
Test object = (Test) new ObjectInputStream(new ByteArrayInputStream(data)).readObject();
System.out.println(object);
}
}