Bug 1309174 - [GSS] (6.4.z) LinkageError due to javax.transaction.xa being in javax.transaction module and system loader
[GSS] (6.4.z) LinkageError due to javax.transaction.xa being in javax.transac...
Status: CLOSED CURRENTRELEASE
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: Class Loading (Show other bugs)
6.4.6
Unspecified Unspecified
unspecified Severity unspecified
: CR1
: EAP 6.4.8
Assigned To: Dmitrii Tikhomirov
Peter Mackay
:
Depends On:
Blocks: 1310484 eap648-payload
  Show dependency treegraph
 
Reported: 2016-02-16 23:48 EST by James Livingston
Modified: 2017-01-17 07:38 EST (History)
8 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2017-01-17 07:38:03 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
bz1309174-test.zip (3.46 KB, application/octet-stream)
2016-04-01 19:45 EDT, dereed
no flags Details


External Trackers
Tracker ID Priority Status Summary Last Updated
JBoss Issue Tracker JBEAP-3340 Blocker Closed javax.transaction/javax.sql class loading is wrong 2017-09-12 10:31 EDT
JBoss Issue Tracker WFLY-6117 Major Resolved Modify javax.transaction.api to exclude the .xa subpackage 2017-09-12 10:31 EDT

  None (edit)
Description James Livingston 2016-02-16 23:48:57 EST
https://issues.jboss.org/browse/WFLY-6117 and linked issues report a problem caused by javax.transaction.xa.* classes being exported by the javax.transaction module which are different from the ones in system loader that javax.sql sees.

After trying a javax.sql module for a while, upstream switched to simply making javax.transaction re-export the system loader's classes, by adding this to the module.xml:
    <exports>
        <exclude path="javax/transaction/xa"/>
    </exports>

    <dependencies>
        <system export="true">
            <paths>
                <path name="javax/transaction/xa"/>
            </paths>
        </system>
    </dependencies>


Although the technical change is quite small, the impact may not be, and we will need to do some decent testing to make sure such a change does not break any rarely used code.
Comment 1 James Livingston 2016-02-16 23:50:57 EST
Dennis noted you can force the problem to occur:

--
I've been able to reproduce the error locally with a simple example class.

    package example;

    import javax.sql.XAConnection;
    import javax.transaction.xa.XAResource;
    import java.sql.Connection;
    import javax.sql.ConnectionEventListener;
    import javax.sql.StatementEventListener;

    public class Test implements XAConnection
    {
       public XAResource getXAResource() { return null; }

        public void addConnectionEventListener( ConnectionEventListener listener ) {}
        public void addStatementEventListener ( StatementEventListener listener ) {}
        public void close () {}
        public Connection getConnection () { return null; }
        public void removeConnectionEventListener ( ConnectionEventListener listener ){}
        public void removeStatementEventListener ( StatementEventListener listener ) {}
    }

Packaged in a module, with the recommended dependencies for the Oracle driver:

        <module name="javax.api"/>
        <module name="javax.transaction.api"/>

If the following three lines are run, in any order, an error occurs in the 3rd one:

    Class.forName ( "javax.transaction.xa.XAResource", true, example.Test.class.getClassLoader() );
    Class.forName ( "javax.transaction.xa.XAResource", true, javax.sql.XAConnection.class.getClassLoader() );
    new example.Test();

If example.Test is last, the error is:

    ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/test].[jsp]] (http-/127.0.0.1:8080-1) JBWEB000236: Servlet.service() for servlet jsp threw exception: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "example.Test.getXAResource()Ljavax/transaction/xa/XAResource;" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class, example/Test, and the class loader (instance of <bootloader>) for interface javax/sql/XAConnection have different Class objects for the type tion/xa/XAResource; used in the signature

If one of the Class.forNames is last, the error is (with a different classloader for each):

    ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/test].[jsp]] (http-/127.0.0.1:8080-1) JBWEB000236: Servlet.service() for servlet jsp threw exception: java.lang.LinkageError: loader constraint violation: loader (instance of org/jboss/modules/ModuleClassLoader) previously initiated loading for a different type with name "javax/transaction/xa/XAResource"
--



A customer experienced this through what appears to be regular usage of a connection, there is likely to be some kind of race where it works unless a variety of classes are loaded in exactly the right order.
Comment 5 dereed 2016-04-01 19:45 EDT
Created attachment 1142722 [details]
bz1309174-test.zip

Attached test case.  See included README for details on running it.
Comment 7 Peter Mackay 2016-05-05 07:58:31 EDT
Verified with EAP 6.4.8.CP.CR2
Comment 8 JBoss JIRA Server 2016-06-14 07:36:05 EDT
Jiri Pallich <jpallich@redhat.com> updated the status of jira JBEAP-3340 to Closed
Comment 9 Petr Penicka 2017-01-17 07:38:03 EST
Retroactively bulk-closing issues from released EAP 6.4 cumulative patches.

Note You need to log in before you can comment on or make changes to this bug.