mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-dfa] IDEA-349054 Ignore current object field nullity inside readResolve()
GitOrigin-RevId: dfe65dc4aa335626874a8b2a01aa68fe627e8ed9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0bed8cf5eb
commit
e19f123a6c
+7
-1
@@ -159,12 +159,18 @@ public final class PlainDescriptor extends PsiVarDescriptor {
|
||||
if (!placeMethod.hasModifierProperty(PsiModifier.STATIC) && target.hasModifierProperty(PsiModifier.STATIC)) return false;
|
||||
if (!target.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
!placeMethod.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
methodCanBeCalledFromConstructorBeforeFieldInitializing(target, placeMethod, placeClass)) {
|
||||
(isReadResolveMethod(placeMethod, placeClass) ||
|
||||
methodCanBeCalledFromConstructorBeforeFieldInitializing(target, placeMethod, placeClass))) {
|
||||
return true;
|
||||
}
|
||||
return getAccessOffset(placeMethod) < getWriteOffset(target);
|
||||
}
|
||||
|
||||
private static boolean isReadResolveMethod(@NotNull PsiMethod method, @NotNull PsiClass aClass) {
|
||||
return "readResolve".equals(method.getName()) && method.getParameterList().isEmpty() &&
|
||||
InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_IO_SERIALIZABLE);
|
||||
}
|
||||
|
||||
private record TargetCallInfo(@NotNull PsiMethod constructor,
|
||||
@NotNull PsiMethodCallExpression call){}
|
||||
private static boolean methodCanBeCalledFromConstructorBeforeFieldInitializing(@NotNull PsiField target,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
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
|
||||
protected Object readResolve() {
|
||||
if (string == null) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,7 @@ public class DataFlowInspection21Test extends DataFlowInspectionTestCase {
|
||||
public void testSuspiciousLabelElementsJava20() {
|
||||
doTest();
|
||||
}
|
||||
public void testReadResolve() { doTest(); }
|
||||
|
||||
public void testForEachPattern() {
|
||||
myFixture.addClass("""
|
||||
|
||||
Reference in New Issue
Block a user