From 77d83bc6acbcef74adb9099ebb6dde809e146125 Mon Sep 17 00:00:00 2001 From: Michael Pfaff Date: Sun, 11 Aug 2024 00:25:30 -0400 Subject: [PATCH] Add missing null check of original model in BufferedMethodBuilder --- .../jdk/internal/classfile/impl/AbstractBuilder.java | 9 +++++++++ .../internal/classfile/impl/AbstractDirectBuilder.java | 7 +++---- .../internal/classfile/impl/BufferedMethodBuilder.java | 10 +++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/java.base/share/classes/jdk/internal/classfile/impl/AbstractBuilder.java diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractBuilder.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractBuilder.java new file mode 100644 index 0000000000000..2f3ee67c36a36 --- /dev/null +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractBuilder.java @@ -0,0 +1,9 @@ +package jdk.internal.classfile.impl; + +public abstract class AbstractBuilder { + protected final M original; + + protected AbstractBuilder(M original) { + this.original = original; + } +} diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractDirectBuilder.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractDirectBuilder.java index 8d00d0609964e..e61e9df23ea40 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractDirectBuilder.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractDirectBuilder.java @@ -27,16 +27,15 @@ import java.lang.classfile.Attribute; import java.lang.classfile.constantpool.ConstantPool; -public class AbstractDirectBuilder { +public abstract class AbstractDirectBuilder extends AbstractBuilder { 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() { diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/BufferedMethodBuilder.java b/src/java.base/share/classes/jdk/internal/classfile/impl/BufferedMethodBuilder.java index 7bf76f7c7a21c..b66c47cce55f3 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/BufferedMethodBuilder.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/BufferedMethodBuilder.java @@ -46,6 +46,7 @@ import java.lang.classfile.constantpool.Utf8Entry; public final class BufferedMethodBuilder + extends AbstractBuilder implements TerminalMethodBuilder { private final List elements; private final SplitConstantPool constantPool; @@ -53,7 +54,6 @@ public final class BufferedMethodBuilder private final Utf8Entry name; private final Utf8Entry desc; private AccessFlags flags; - private final MethodModel original; private int[] parameterSlots; @Stable MethodTypeDesc mDesc; @@ -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 @@ -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; }