Skip to content

Commit

Permalink
Merge pull request #45528 from zakkak/2025-01-13-narayana-registrations
Browse files Browse the repository at this point in the history
Register public constructors for Narayana classes
  • Loading branch information
geoand authored Jan 13, 2025
2 parents 4ce7fcd + 81248e7 commit 429c2d0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class ReflectiveClassBuildItem extends MultiBuildItem {
private final boolean fields;
private final boolean classes;
private final boolean constructors;
private final boolean publicConstructors;
private final boolean queryConstructors;
private final boolean weak;
private final boolean serialization;
Expand All @@ -46,7 +47,7 @@ public static Builder builder(String... classNames) {
private ReflectiveClassBuildItem(boolean constructors, boolean queryConstructors, boolean methods, boolean queryMethods,
boolean fields, boolean getClasses, boolean weak, boolean serialization, boolean unsafeAllocated, String reason,
Class<?>... classes) {
this(constructors, queryConstructors, methods, queryMethods, fields, getClasses, weak, serialization,
this(constructors, false, queryConstructors, methods, queryMethods, fields, getClasses, weak, serialization,
unsafeAllocated, reason, stream(classes).map(Class::getName).toArray(String[]::new));
}

Expand Down Expand Up @@ -118,11 +119,12 @@ public static ReflectiveClassBuildItem serializationClass(String... classNames)
ReflectiveClassBuildItem(boolean constructors, boolean queryConstructors, boolean methods, boolean queryMethods,
boolean fields, boolean weak, boolean serialization,
boolean unsafeAllocated, String... className) {
this(constructors, queryConstructors, methods, queryMethods, fields, false, weak, serialization, unsafeAllocated,
this(constructors, false, queryConstructors, methods, queryMethods, fields, false, weak, serialization, unsafeAllocated,
null, className);
}

ReflectiveClassBuildItem(boolean constructors, boolean queryConstructors, boolean methods, boolean queryMethods,
ReflectiveClassBuildItem(boolean constructors, boolean publicConstructors, boolean queryConstructors, boolean methods,
boolean queryMethods,
boolean fields, boolean classes, boolean weak, boolean serialization,
boolean unsafeAllocated, String reason, String... className) {
for (String i : className) {
Expand All @@ -143,6 +145,7 @@ public static ReflectiveClassBuildItem serializationClass(String... classNames)
this.fields = fields;
this.classes = classes;
this.constructors = constructors;
this.publicConstructors = publicConstructors;
if (constructors && queryConstructors) {
Log.warnf(
"Both constructors and queryConstructors are set to true for classes: %s. queryConstructors is redundant and will be ignored",
Expand Down Expand Up @@ -181,6 +184,10 @@ public boolean isConstructors() {
return constructors;
}

public boolean isPublicConstructors() {
return publicConstructors;
}

public boolean isQueryConstructors() {
return queryConstructors;
}
Expand Down Expand Up @@ -213,6 +220,7 @@ public String getReason() {
public static class Builder {
private String[] className;
private boolean constructors = true;
private boolean publicConstructors = false;
private boolean queryConstructors;
private boolean methods;
private boolean queryMethods;
Expand Down Expand Up @@ -244,6 +252,19 @@ public Builder constructors() {
return constructors(true);
}

/**
* Configures whether public constructors should be registered for reflection.
* Setting this enables getting all public constructors for the class as well as invoking them reflectively.
*/
public Builder publicConstructors(boolean publicConstructors) {
this.publicConstructors = publicConstructors;
return this;
}

public Builder publicConstructors() {
return publicConstructors(true);
}

/**
* Configures whether constructors should be registered for reflection, for query purposes only.
* Setting this enables getting all declared constructors for the class but does not allow invoking them reflectively.
Expand Down Expand Up @@ -358,7 +379,8 @@ public Builder unsafeAllocated() {
}

public ReflectiveClassBuildItem build() {
return new ReflectiveClassBuildItem(constructors, queryConstructors, methods, queryMethods, fields, classes, weak,
return new ReflectiveClassBuildItem(constructors, publicConstructors, queryConstructors, methods, queryMethods,
fields, classes, weak,
serialization, unsafeAllocated, reason, className);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ void generateReflectConfig(BuildProducer<GeneratedResourceBuildItem> reflectConf
extractToJsonArray(info.ctorSet, methodsArray);
}
}
if (info.publicConstructors) {
json.put("allPublicConstructors", true);
}
if (info.methods) {
json.put("allDeclaredMethods", true);
} else {
Expand Down Expand Up @@ -246,6 +249,7 @@ public void addReflectiveField(Map<String, ReflectionInfo> reflectiveClasses, Re

static final class ReflectionInfo {
boolean constructors;
boolean publicConstructors;
boolean queryConstructors;
boolean methods;
boolean queryMethods;
Expand All @@ -270,6 +274,7 @@ private ReflectionInfo(ReflectiveClassBuildItem classBuildItem, String typeReach
this.classes = classBuildItem.isClasses();
this.typeReachable = typeReachable;
this.constructors = classBuildItem.isConstructors();
this.publicConstructors = classBuildItem.isPublicConstructors();
this.queryConstructors = classBuildItem.isQueryConstructors();
this.serialization = classBuildItem.isSerialization();
this.unsafeAllocated = classBuildItem.isUnsafeAllocated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void build(NarayanaJtaRecorder recorder,
JTANodeNameXAResourceOrphanFilter.class,
JTAActionStatusServiceXAResourceOrphanFilter.class,
ExpiredTransactionStatusManagerScanner.class)
.publicConstructors()
.reason(getClass().getName())
.build());

Expand Down

0 comments on commit 429c2d0

Please sign in to comment.