GcfJarLayout omits GcfJarLauncher$NestedUrlStreamHandlerFactory, causing NoClassDefFoundError under the GCF invoker
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 32/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- java
- Domínio
- build-system
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Java
- Estrelas
- 1.1k
- Forks
- 655
- Merge médio
- 4h 54min
- PRs com merge (30d)
- 10
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de spring-cloud/spring-cloud-function
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
spring-cloud/spring-cloud-function#1542 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
spring-cloud/spring-cloud-function#1538 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Kotlin function wrapper treats empty input as no inputTalvez já em andamento @seonwooj0810 assumiu hoje. Aberta5.0.x backport bug
Dificuldade 3/5 Meio dia Facilidade para iniciantes 30/100
spring-cloud/spring-cloud-function#1537 ·
Mantenedores costumam responder em até 1 dia
-
Default JSON mapper collection limit is hard-coded and replaces all collection deserializationAberta5.0.x backport bug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 22/100
spring-cloud/spring-cloud-function#1536 ·
Mantenedores costumam responder em até 1 dia
-
SmartCompositeMessageConverter fails with NullPointerException or ClassCastException in several conversion pathsTalvez já em andamento @seonwooj0810 assumiu há 1 dia. Aberta5.0.x backport bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
spring-cloud/spring-cloud-function#1535 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de spring-cloud/spring-cloud-function
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
-
bug devops low
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
-
enhancement
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 88/100
MDMesh-app/MDMesh#252 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 80/100
Mantenedores costumam responder em até 1 dia