Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchFileException when instantiating Smooks #768

Closed
bpicode opened this issue Apr 16, 2024 · 3 comments
Closed

NoSuchFileException when instantiating Smooks #768

bpicode opened this issue Apr 16, 2024 · 3 comments
Assignees
Labels
priority: medium type: bug Something isn't working
Milestone

Comments

@bpicode
Copy link

bpicode commented Apr 16, 2024

Describe the bug

An exception occurs when constructing a new Smooks instance

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.smooks.Smooks]: Factory method 'smooks' threw exception with message: nested:/path/to/myapplication.jar
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:177)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644)
	... 68 common frames omitted
Caused by: org.smooks.api.SmooksException: nested:/path/to/myapplication.jar
	at org.smooks.engine.DefaultApplicationContext.<init>(DefaultApplicationContext.java:93)
	at org.smooks.engine.DefaultApplicationContextBuilder.build(DefaultApplicationContextBuilder.java:90)
	at org.smooks.Smooks.<init>(Smooks.java:152)
    ....
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at cloud.rio.dispatch.ediconverter.configuration.SmooksConfig$$SpringCGLIB$$0.smooksD20B(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140)
	... 69 common frames omitted
Caused by: java.nio.file.NoSuchFileException: nested:/path/to/myapplication.jar
	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
	at java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
	at java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:148)
	at java.base/sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:99)
	at java.base/java.nio.file.Files.readAttributes(Files.java:1851)
	at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1428)
	at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:718)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:252)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:181)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:195)
	at org.smooks.classpath.Scanner.handleArchive(Scanner.java:121)
	at org.smooks.classpath.Scanner.scanClasspath(Scanner.java:104)
	at org.smooks.engine.DefaultApplicationContext.<init>(DefaultApplicationContext.java:91)
	... 82 common frames omitted

I did a little digging and found that the handling of URLs in org.smooks.classpath.Scanner#scanClasspath

public void scanClasspath(ClassLoader classLoader) throws IOException {

        if (!(classLoader instanceof URLClassLoader)) {
            LOGGER.warn("Not scanning classpath for ClassLoader '" + classLoader.getClass().getName() + "'.  ClassLoader must implement '" + URLClassLoader.class.getName() + "'.");
            return;
        }

        URL[] urls = ((URLClassLoader) classLoader).getURLs();
        Set<String> alreadyScanned = new HashSet<String>();

        for (URL url : urls) {
            String urlPath = url.getFile();

            urlPath = URLDecoder.decode(urlPath, "UTF-8");
            if (urlPath.startsWith("file:")) {
                urlPath = urlPath.substring(5);
            }

            if (urlPath.indexOf('!') > 0) {
                urlPath = urlPath.substring(0, urlPath.indexOf('!'));
            }

            File file = new File(urlPath);
            if(alreadyScanned.contains(file.getAbsolutePath())) {
                LOGGER.debug("Ignoring classpath URL '" + file.getAbsolutePath() + "'.  Already scanned this URL.");
                continue;
            } if (file.isDirectory()) {
                handleDirectory(file, null);
            } else {
                handleArchive(file);
            }
            alreadyScanned.add(file.getAbsolutePath());
        }
    }

is incompatible with the class loader from spring boot, see spring-projects/spring-boot@7ad4a98. In the commit it was mentioned that

Jar URLs now use the form jar:nested:/my.jar/!nested.jar!/entry

This seems to be the root of the java.nio.file.NoSuchFileException: nested:/path/to/myapplication.jar.

To Reproduce

Create a spring boot project (v3.2.4) and create a bean of type Smooks.

Expected behavior

Instantiating Smooks works with class loaders from spring boot without the aforementioned exception.

Environment

  • Smooks: tried it with 2.0.0-M3, 2.0.0-RC2, 2.0.0-RC2
  • Spring-boot: 3.2.4
  • Java: java-17-amazon-corretto
  • OS: Ubuntu

Sample

Don't have one at the moment. Can do if required.

@cjmamo cjmamo self-assigned this Apr 16, 2024
@cjmamo
Copy link
Member

cjmamo commented Apr 16, 2024

This might have been fixed in #480. Could you try RC3? RC4 will have this scanning behaviour removed since there's no point to it: https://groups.google.com/g/smooks-user/c/hLen9nplpMo/m/EUccz3d0AwAJ .

@cjmamo cjmamo added the type: bug Something isn't working label Apr 16, 2024
@bpicode
Copy link
Author

bpicode commented Apr 17, 2024

Yes, I tried it with RC3, same effect. So I need to wait until RC4 is released?

@cjmamo cjmamo added this to the v2.0.0-RC4 milestone Apr 17, 2024
@cjmamo
Copy link
Member

cjmamo commented Apr 18, 2024

Yes. RC4 was released today. Please read the announcement: https://groups.google.com/g/smooks-user/c/JhplstPZrqo

@cjmamo cjmamo closed this as completed Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium type: bug Something isn't working
Development

No branches or pull requests

2 participants