Skip to content

Commit

Permalink
Add missing null check of original model in BufferedMethodBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfaff committed Aug 11, 2024
1 parent 5d24db4 commit 77d83bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package jdk.internal.classfile.impl;

public abstract class AbstractBuilder<M> {
protected final M original;

protected AbstractBuilder(M original) {
this.original = original;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@
import java.lang.classfile.Attribute;
import java.lang.classfile.constantpool.ConstantPool;

public class AbstractDirectBuilder<M> {
public abstract class AbstractDirectBuilder<M> extends AbstractBuilder<M> {
protected final SplitConstantPool constantPool;
protected final ClassFileImpl context;
protected final AttributeHolder attributes = new AttributeHolder();
protected final M original;

public AbstractDirectBuilder(SplitConstantPool constantPool, ClassFileImpl context, M original) {
protected AbstractDirectBuilder(SplitConstantPool constantPool, ClassFileImpl context, M original) {
super(original);
this.constantPool = constantPool;
this.context = context;
this.original = original;
}

public SplitConstantPool constantPool() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
import java.lang.classfile.constantpool.Utf8Entry;

public final class BufferedMethodBuilder
extends AbstractBuilder<MethodModel>
implements TerminalMethodBuilder {
private final List<MethodElement> elements;
private final SplitConstantPool constantPool;
private final ClassFileImpl context;
private final Utf8Entry name;
private final Utf8Entry desc;
private AccessFlags flags;
private final MethodModel original;
private int[] parameterSlots;
@Stable
MethodTypeDesc mDesc;
Expand All @@ -64,13 +64,13 @@ public BufferedMethodBuilder(SplitConstantPool constantPool,
Utf8Entry typeInfo,
int flags,
MethodModel original) {
super(original);
this.elements = new ArrayList<>();
this.constantPool = constantPool;
this.context = context;
this.name = nameInfo;
this.desc = typeInfo;
this.flags = new AccessFlagsImpl(AccessFlag.Location.METHOD, flags);
this.original = original;
}

@Override
Expand Down Expand Up @@ -106,7 +106,11 @@ public Utf8Entry methodType() {
@Override
public MethodTypeDesc methodTypeSymbol() {
if (mDesc == null) {
mDesc = original.methodTypeSymbol();
if (original != null) {
mDesc = original.methodTypeSymbol();
} else {
mDesc = MethodTypeDesc.ofDescriptor(methodType().stringValue());
}
}
return mDesc;
}
Expand Down

0 comments on commit 77d83bc

Please sign in to comment.