Fixing EA-50643 - NPE: PropertyCodegen.generateBackingField
Do not return null as a method/field visitor
This commit is contained in:
@@ -19,12 +19,12 @@ package org.jetbrains.jet.codegen;
|
|||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.asm4.AnnotationVisitor;
|
import org.jetbrains.asm4.*;
|
||||||
import org.jetbrains.asm4.ClassVisitor;
|
|
||||||
import org.jetbrains.asm4.FieldVisitor;
|
|
||||||
import org.jetbrains.asm4.MethodVisitor;
|
|
||||||
|
|
||||||
public abstract class ClassBuilder {
|
public abstract class ClassBuilder {
|
||||||
|
protected static final MethodVisitor EMPTY_METHOD_VISITOR = new MethodVisitor(Opcodes.ASM4) {};
|
||||||
|
protected static final FieldVisitor EMPTY_FIELD_VISITOR = new FieldVisitor(Opcodes.ASM4) {};
|
||||||
|
|
||||||
private String thisName;
|
private String thisName;
|
||||||
|
|
||||||
private final MemberMap members = new MemberMap();
|
private final MemberMap members = new MemberMap();
|
||||||
@@ -43,6 +43,7 @@ public abstract class ClassBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public FieldVisitor newField(
|
public FieldVisitor newField(
|
||||||
@Nullable PsiElement origin,
|
@Nullable PsiElement origin,
|
||||||
int access,
|
int access,
|
||||||
@@ -51,9 +52,14 @@ public abstract class ClassBuilder {
|
|||||||
@Nullable String signature,
|
@Nullable String signature,
|
||||||
@Nullable Object value
|
@Nullable Object value
|
||||||
) {
|
) {
|
||||||
return getVisitor().visitField(access, name, desc, signature, value);
|
FieldVisitor visitor = getVisitor().visitField(access, name, desc, signature, value);
|
||||||
|
if (visitor == null) {
|
||||||
|
return EMPTY_FIELD_VISITOR;
|
||||||
|
}
|
||||||
|
return visitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public MethodVisitor newMethod(
|
public MethodVisitor newMethod(
|
||||||
@Nullable PsiElement origin,
|
@Nullable PsiElement origin,
|
||||||
int access,
|
int access,
|
||||||
@@ -62,7 +68,11 @@ public abstract class ClassBuilder {
|
|||||||
@Nullable String signature,
|
@Nullable String signature,
|
||||||
@Nullable String[] exceptions
|
@Nullable String[] exceptions
|
||||||
) {
|
) {
|
||||||
return getVisitor().visitMethod(access, name, desc, signature, exceptions);
|
MethodVisitor visitor = getVisitor().visitMethod(access, name, desc, signature, exceptions);
|
||||||
|
if (visitor == null) {
|
||||||
|
return EMPTY_METHOD_VISITOR;
|
||||||
|
}
|
||||||
|
return visitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ public class StubClassBuilder extends ClassBuilder {
|
|||||||
((StubBase) v.getResult()).putUserData(ClsWrapperStubPsiFactory.ORIGIN_ELEMENT, origin);
|
((StubBase) v.getResult()).putUserData(ClsWrapperStubPsiFactory.ORIGIN_ELEMENT, origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public MethodVisitor newMethod(
|
public MethodVisitor newMethod(
|
||||||
@Nullable PsiElement origin,
|
@Nullable PsiElement origin,
|
||||||
@@ -107,7 +108,7 @@ public class StubClassBuilder extends ClassBuilder {
|
|||||||
) {
|
) {
|
||||||
MethodVisitor internalVisitor = super.newMethod(origin, access, name, desc, signature, exceptions);
|
MethodVisitor internalVisitor = super.newMethod(origin, access, name, desc, signature, exceptions);
|
||||||
|
|
||||||
if (internalVisitor != null) {
|
if (internalVisitor != EMPTY_METHOD_VISITOR) {
|
||||||
// If stub for method generated
|
// If stub for method generated
|
||||||
markLastChild(origin);
|
markLastChild(origin);
|
||||||
}
|
}
|
||||||
@@ -115,6 +116,7 @@ public class StubClassBuilder extends ClassBuilder {
|
|||||||
return internalVisitor;
|
return internalVisitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public FieldVisitor newField(
|
public FieldVisitor newField(
|
||||||
@Nullable PsiElement origin,
|
@Nullable PsiElement origin,
|
||||||
@@ -126,7 +128,7 @@ public class StubClassBuilder extends ClassBuilder {
|
|||||||
) {
|
) {
|
||||||
FieldVisitor internalVisitor = super.newField(origin, access, name, desc, signature, value);
|
FieldVisitor internalVisitor = super.newField(origin, access, name, desc, signature, value);
|
||||||
|
|
||||||
if (internalVisitor != null) {
|
if (internalVisitor != EMPTY_FIELD_VISITOR) {
|
||||||
// If stub for field generated
|
// If stub for field generated
|
||||||
markLastChild(origin);
|
markLastChild(origin);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user