Skip to content

Spring Boot 4.0.0 / Spring Cloud Function 5.0.0 (GCP Adapter) fails with unknown protocol: nested on deployment #1320

@compl-snd

Description

@compl-snd

Description:

After upgrading our application from Spring Boot 3.5.8 to 4.0.0 and Spring Cloud Function 4.3.0 to 5.0.0, the deployment of our Spring Cloud Function using the spring-cloud-function-adapter-gcp fails immediately upon initialisation within the Google Cloud Functions (GCF) environment. The function continues to run perfectly fine locally using the Function Maven plugin.

The failure occurs during the construction of the GCF Adapter class, which is unable to resolve resources within the executable JAR's nested dependencies, leading to a MalformedURLException: unknown protocol: nested root cause message. The error seems to indicate that the GCF Invoker's classloader is initialized without the custom nested URL protocol handler required to unpack dependencies from the standard Spring Boot executable JAR format. I'm assuming the issue is related to Spring dropping the classic uber-jar loader support in the latest release?

Full Stack Trace:

"Exception in thread "main" java.lang.RuntimeException: Could not construct an instance of org.springframework.cloud.function.adapter.gcp.GcfJarLauncher: java.lang.reflect.InvocationTargetException
	at com.google.cloud.functions.invoker.BackgroundFunctionExecutor.forClass(BackgroundFunctionExecutor.java:127)
	at com.google.cloud.functions.invoker.BackgroundFunctionExecutor.forClass(BackgroundFunctionExecutor.java:117)
	at com.google.cloud.functions.invoker.runner.Invoker.startServer(Invoker.java:314)
	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.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:74)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
	at com.google.cloud.functions.invoker.BackgroundFunctionExecutor.forClass(BackgroundFunctionExecutor.java:124)
	... 4 more
Caused by: java.lang.ExceptionInInitializerError
	at org.springframework.boot.loader.net.protocol.jar.Handler.openConnection(Handler.java:46)
	at java.base/java.net.URL.openConnection(URL.java:1209)
	at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.getJarFile(JarUrlClassLoader.java:183)
	at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.definePackage(JarUrlClassLoader.java:146)
	at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.definePackageIfNecessary(JarUrlClassLoader.java:129)
	at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:102)
	at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:490)
	at org.springframework.cloud.function.adapter.gcp.GcfJarLauncher.<init>(GcfJarLauncher.java:46)
	at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
	... 7 more
Caused by: java.lang.IllegalStateException: java.net.MalformedURLException: unknown protocol: nested
	at org.springframework.boot.loader.net.protocol.jar.JarUrlConnection.<clinit>(JarUrlConnection.java:67)
	... 17 more
Caused by: java.net.MalformedURLException: unknown protocol: nested
	at java.base/java.net.URL.<init>(URL.java:742)
	at java.base/java.net.URL.<init>(URL.java:630)
	at java.base/java.net.URL.<init>(URL.java:566)
	at java.base/java.net.JarURLConnection.parseJarFileURL(JarURLConnection.java:188)
	at java.base/java.net.JarURLConnection.<init>(JarURLConnection.java:170)
	at org.springframework.boot.loader.net.protocol.jar.JarUrlConnection.<init>(JarUrlConnection.java:92)
	at org.springframework.boot.loader.net.protocol.jar.JarUrlConnection.<clinit>(JarUrlConnection.java:64)
	... 17 more"

Workaround:

Further testing revealed that explicitly restoring the spring-cloud-function-adapter-gcp to 4.3.0 and the spring-boot-maven-plugin to version 3.5.8, while keeping the rest of the application dependencies on the Spring Boot 4.x line, fixed the issue for me.

This all is largely unknown territory for me, but I thought this was worth reporting anyway. I can't easily share an MRE currently, but happy to provide any more details where possible 👍.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions