Skip to content

Commit

Permalink
Merge pull request #10 from zakkak/2024-08-21-backport-custom-cons
Browse files Browse the repository at this point in the history
Backport: Allow custom constructors for arrays and enums
  • Loading branch information
zakkak authored Aug 28, 2024
2 parents 14a73c8 + 1b0c49c commit fe54a9a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
public final class MissingSerializationRegistrationUtils {

public static void missingSerializationRegistration(Class<?> cl, String... msg) {
report(new MissingSerializationRegistrationError(errorMessage(msg), cl));
MissingSerializationRegistrationError exception = new MissingSerializationRegistrationError(errorMessage(msg), cl);
StackTraceElement responsibleClass = getResponsibleClass(exception);
MissingRegistrationUtils.report(exception, responsibleClass);
}

private static String errorMessage(String... type) {
Expand All @@ -55,11 +57,6 @@ private static String errorMessage(String... type) {
.formatted(typeStr);
}

private static void report(MissingSerializationRegistrationError exception) {
StackTraceElement responsibleClass = getResponsibleClass(exception);
MissingRegistrationUtils.report(exception, responsibleClass);
}

/*
* This is a list of all public JDK methods that end up potentially throwing missing
* registration errors. This should be implemented using wrapping substitutions once they are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Object getSerializationConstructorAccessor(Class<?> rawDeclaringClass, Cl
String targetConstructorClassName = targetConstructorClass.getName();
if (ThrowMissingRegistrationErrors.hasBeenSet()) {
MissingSerializationRegistrationUtils.missingSerializationRegistration(declaringClass,
"type " + declaringClass.getName() + " with target constructor class: " + targetConstructorClassName);
"type " + declaringClass.getTypeName() + " with target constructor class: " + targetConstructorClassName);
} else {
throw VMError.unsupportedFeature("SerializationConstructorAccessor class not found for declaringClass: " + declaringClass.getName() +
" (targetConstructorClass: " + targetConstructorClassName + "). Usually adding " + declaringClass.getName() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,6 @@ private static Constructor<?> getExternalizableConstructor(Class<?> serializatio

Class<?> addConstructorAccessor(Class<?> serializationTargetClass, Class<?> customTargetConstructorClass) {
serializationSupport.registerSerializationTargetClass(serializationTargetClass);
if (serializationTargetClass.isArray() || Enum.class.isAssignableFrom(serializationTargetClass)) {
return null;
}

// Don't generate SerializationConstructorAccessor class for Externalizable case
if (Externalizable.class.isAssignableFrom(serializationTargetClass)) {
Expand Down

0 comments on commit fe54a9a

Please sign in to comment.