Skip to content

Commit

Permalink
IGNITE-22952 Fix lambda classname parsing in deployment for Java 21+ (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ibessonov authored Aug 8, 2024
1 parent 3b8e513 commit e5a199f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ private void processResourceRequest(UUID nodeId, GridDeploymentRequest req) {
// In case the class loader is ours - skip the check
// since it was already performed before (and was successful).
if (!(ldr instanceof GridDeploymentClassLoader)) {
// First check for @GridNotPeerDeployable annotation.
String clsName = req.resourceName().replace('/', '.');
String clsName = clsNameFromResourceName(req.resourceName());

try {
if (clsName.endsWith(CLASS_FILE_EXTENSION))
clsName = clsName.substring(0, clsName.length() - CLASS_FILE_EXTENSION.length());

Class<?> cls = Class.forName(clsName, true, ldr);

// First check for @GridNotPeerDeployable annotation.
if (U.getAnnotation(cls, IgniteNotPeerDeployable.class) != null) {
String errMsg = "Attempt to peer deploy class that has @IgniteNotPeerDeployable " +
"annotation: " + clsName;
Expand Down Expand Up @@ -294,6 +294,17 @@ private void processResourceRequest(UUID nodeId, GridDeploymentRequest req) {
sendResponse(nodeId, req.responseTopic(), res);
}

/** */
private static String clsNameFromResourceName(String reqResourceName) {
String clsName = reqResourceName.replace('/', '.');

// Java 21+ uses '/' in lambda class names, we must account for that.
if (!reqResourceName.contains("$$Lambda/"))
return clsName;

return clsName.replace("$$Lambda.", "$$Lambda/");
}

/** */
private String resourceRequestDetails(UUID nodeId, GridDeploymentRequest req) {
return new SB()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10088,9 +10088,13 @@ public static IgniteCheckedException exceptionWithSuppressed(String msg, @Nullab
* {@code null} if passed in name is not related to lambda.
*/
@Nullable public static String lambdaEnclosingClassName(String clsName) {
int idx = clsName.indexOf("$$Lambda$");
int idx0 = clsName.indexOf("$$Lambda$"); // Java 8+
int idx1 = clsName.indexOf("$$Lambda/"); // Java 21+

return idx != -1 ? clsName.substring(0, idx) : null;
if (idx0 == idx1)
return null;

return clsName.substring(0, idx0 >= 0 ? idx0 : idx1);
}

/**
Expand Down

0 comments on commit e5a199f

Please sign in to comment.