GcfJarLayout omits GcfJarLauncher$NestedUrlStreamHandlerFactory, causing NoClassDefFoundError under the GCF invoker
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 32/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- java
- Domaine
- build-system
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Java
- Étoiles
- 1.1k
- Forks
- 655
- Merge moyen
- 4 h 54 min
- PR mergées (30 j)
- 10
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de spring-cloud/spring-cloud-function
-
ClassCastException with spring-cloud-function 4.3.6 when a field of type Set is deserializedOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
spring-cloud/spring-cloud-function#1542 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
spring-cloud/spring-cloud-function#1538 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Kotlin function wrapper treats empty input as no inputPeut-être pris @seonwooj0810 l’a pris aujourd’hui. Ouverte5.0.x backport bug
Difficulté 3/5 Une demi-journée Accessibilité débutants 30/100
spring-cloud/spring-cloud-function#1537 ·
Les mainteneurs répondent en général sous 1 jour
-
Default JSON mapper collection limit is hard-coded and replaces all collection deserializationOuverte5.0.x backport bug
Difficulté 4/5 3-5 jours Accessibilité débutants 22/100
spring-cloud/spring-cloud-function#1536 ·
Les mainteneurs répondent en général sous 1 jour
-
SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion pathsPeut-être pris @seonwooj0810 l’a pris il y a 1 jour. Ouverte5.0.x backport bug
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
spring-cloud/spring-cloud-function#1535 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de spring-cloud/spring-cloud-function
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
bug devops low
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
-
enhancement
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
MDMesh-app/MDMesh#252 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 80/100
Les mainteneurs répondent en général sous 1 jour