[ 
https://issues.apache.org/jira/browse/LOG4J2-834?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14228817#comment-14228817
 ] 

Thiago Kronig commented on LOG4J2-834:
--------------------------------------

I did the following steps to build the patch:
- {{git clone http://git-wip-us.apache.org/repos/asf/logging-log4j2.git}}
- created a branch named after this issue, {{git checkout -b LOG4J2-834}}
- create two java files, an interface [^InexistentInterface.java], and a class 
which implemets it, [^ForceNoDefClassFoundError.java]
- compiled the two and run `main` from ForceNoDefClassFoundError, which throws 
a RuntimeException and serializes it to base64 format
- copied only the class file for ForceNoDefClassFoundError to the test 
resources directory, so that it`ll be available at test runtime, but also be 
unloadable, because of the absence of InexistentInterface in the classpath.
- create the java test case, ensuring that it throws NoClassDefFoundError
- fix the bug and run the test case again, confirming it.
- commit
- create patch using: {{git format-patch master --binary}}

Sorry for not given enough clarification earlier.

> NoClassDefFoundError in ThrowableProxy
> --------------------------------------
>
>                 Key: LOG4J2-834
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-834
>             Project: Log4j 2
>          Issue Type: Bug
>            Reporter: Nikita Koval
>         Attachments: 
> 0001-LOG4J2-834-Ignores-NoClassDefFoundError-and-other-Th.patch, 
> ForceNoDefClassFoundError.java, InexistentInterface.java
>
>
> In method *loadClass* we expect {{ClassNotFoundException}}. But if class 
> comes from another java machine we can get {{NoClassDefFoundError}}.
> Possible fix:
> {code:java}
> private Class<?> loadClass(final ClassLoader lastLoader, final String 
> className) {
>        // XXX: this is overly complicated
>        Class<?> clazz;
>        if (lastLoader != null) {
>            try {
>                clazz = Loader.initializeClass(className, lastLoader);
>                if (clazz != null) {
>                    return clazz;
>                }
>            } catch (final Throwable ignore) {
>                // Ignore exception.
>            }
>        }
>        try {
>            clazz = Loader.loadClass(className);
>        } catch (final ClassNotFoundException | LinkageError ignored) {
>            try {
>                clazz = Loader.initializeClass(className, 
> this.getClass().getClassLoader());
>            } catch (final ClassNotFoundException | LinkageError ignore) {
>                return null;
>            }
>        }
>        return clazz;
>    }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to