GcfJarLayout omits GcfJarLauncher$NestedUrlStreamHandlerFactory, causing NoClassDefFoundError under the GCF invoker
維護者通常 1 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 32/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- java
- 領域
- build-system
研究方向
Start in GcfJarLayout.writeLoadedClasses in the GCP adapter module: it copies only GcfJarLauncher.class to the repackaged jar root, while the launcher's static initializer now also references GcfJarLauncher$NestedUrlStreamHandlerFactory. Read that writer and the module's existing layout tests, then rebuild and run the invoker command from the report against a sample jar; done means the invoker starts and the function answers HELLO. Note that #1548 already proposes a change, so check it before starting.
由索引模型根據 Issue 內容生成。
描述
This is a follow-up to #1336. Its fix (present in 5.1.0) added a private static nested class, GcfJarLauncher$NestedUrlStreamHandlerFactory, to GcfJarLauncher. However, GcfJarLayout.writeLoadedClasses still copies only GcfJarLauncher.class to the root of the repackaged jar.
The Google Cloud Functions Java invoker loads GcfJarLauncher from the jar root, so initializing its static NESTED_URL_STREAM_HANDLER_FACTORY field fails because the nested class is not there:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/cloud/function/adapter/gcp/GcfJarLauncher$NestedUrlStreamHandlerFactory
at org.springframework.cloud.function.adapter.gcp.GcfJarLauncher.<clinit>(GcfJarLauncher.java:43)
...
at com.google.cloud.functions.invoker.HttpFunctionExecutor.forClass(HttpFunctionExecutor.java:54)
at com.google.cloud.functions.invoker.runner.Invoker.servletForDeducedSignatureType(Invoker.java:381)
at com.google.cloud.functions.invoker.runner.Invoker.startServer(Invoker.java:302)
at com.google.cloud.functions.invoker.runner.Invoker.startServer(Invoker.java:248)
at com.google.cloud.functions.invoker.runner.Invoker.main(Invoker.java:131)
Caused by: java.lang.ClassNotFoundException: org.springframework.cloud.function.adapter.gcp.GcfJarLauncher$NestedUrlStreamHandlerFactory
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
... 14 more
A minimal reproducible example:
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.2.0</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>gcf-nested-handler-repro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>21</java.version>
<spring-cloud-function.version>5.1.0</spring-cloud-function.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-gcp</artifactId>
<version>${spring-cloud-function.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<outputDirectory>target/deploy</outputDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-gcp</artifactId>
<version>${spring-cloud-function.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
src/main/java/com/example/demo/DemoApplication.java:
package com.example.demo;
import java.util.function.Function;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
public Function<String, String> uppercase() {
return String::toUpperCase;
}
}
Steps to reproduce:
mvn clean package
mvn dependency:copy -Dartifact=com.google.cloud.functions.invoker:java-function-invoker:1.3.3 -DoutputDirectory=target
java -jar target/java-function-invoker-1.3.3.jar \
--classpath target/deploy/gcf-nested-handler-repro-0.0.1-SNAPSHOT.jar \
--target org.springframework.cloud.function.adapter.gcp.GcfJarLauncher \
--port 8080
Expected: the invoker starts and curl -X POST -H 'Content-Type: text/plain' -d hello http://localhost:8080/ returns HELLO.
Actual: the invoker exits immediately with the NoClassDefFoundError above.
- 主要語言
- Java
- 星號
- 1.1k
- 分支
- 655
- 平均合併
- 4 小時 54 分鐘
- 30 天內合併 PR
- 10
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
spring-cloud/spring-cloud-function 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 70/100
spring-cloud/spring-cloud-function#1542 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 55/100
spring-cloud/spring-cloud-function#1538 · 1 則留言 ·
維護者通常 1 天內回覆
-
Kotlin function wrapper treats empty input as no input可能已有人在做 @seonwooj0810 今天認領。 未關閉5.0.x backport bug
難度 3/5 半天 新手友好度 30/100
spring-cloud/spring-cloud-function#1537 ·
維護者通常 1 天內回覆
-
5.0.x backport bug
難度 4/5 3-5 天 新手友好度 22/100
spring-cloud/spring-cloud-function#1536 ·
維護者通常 1 天內回覆
-
SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion paths可能已有人在做 @seonwooj0810 於 1 天前認領。 未關閉5.0.x backport bug
難度 3/5 1-2 天 新手友好度 35/100
spring-cloud/spring-cloud-function#1535 ·
維護者通常 1 天內回覆
查看 spring-cloud/spring-cloud-function 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 62/100
-
難度 1/5 1 小時以內 新手友好度 80/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
aphtech/brailleblaster#209 ·
維護者通常 1 天內回覆
-
payers.csv writes QOLS_AVG as NaN for every payer that had no members可能已有人在做 @DG47 今天認領。 未關閉
難度 1/5 1 小時以內 新手友好度 86/100
synthetichealth/synthea#1797 ·
維護者通常 19 天內回覆
-
build enhancement security
難度 2/5 1-3 小時 新手友好度 78/100
midhunhk/lib-aeapps#54 ·