groovy
  1. groovy
  2. GROOVY-3495

LinkageError when obtaining a Cipher instance in a multithreaded environment

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.1
    • Fix Version/s: 1.8.2, 1.9-beta-3, 1.7.11
    • Component/s: None
    • Labels:
      None
    • Environment:
      Using BouncyCastle as security provider
    • Number of attachments :
      0

      Description

      When obtaining a Cipher instance the Groovy rootLoader can throw a LinkageError in relation to the provider implementation classes if multiple threads try get such a Cipher instance.

      No unit test as I can't reliably reproduce the effect...
      An example script to illustrate the issue (may need to run multiple times):

      import javax.crypto.Cipher
      import org.bouncycastle.jce.provider.BouncyCastleProvider
      import java.security.Security

      Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider())

      def getCipherInstance = {Cipher.getInstance("Blowfish/ECB/PKCS5Padding", BouncyCastleProvider.PROVIDER_NAME)}

      new Thread(getCipherInstance).start()
      new Thread(getCipherInstance).start()

      And the exception:

      Exception in thread "Thread-2" org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.LinkageError: loader (instance of org/codehaus/groovy/tools/RootLoader): attempted duplicate class definition for name: "org/bouncycastle/jce/provider/JCEBlockCipher$Blowfish"
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:92)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893)
      at groovy.lang.Closure.call(Closure.java:279)
      at groovy.lang.Closure.call(Closure.java:274)
      at groovy.lang.Closure.run(Closure.java:355)
      at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.LinkageError: loader (instance of org/codehaus/groovy/tools/RootLoader): attempted duplicate class definition for name: "org/bouncycastle/jce/provider/JCEBlockCipher$Blowfish"
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
      at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at org.codehaus.groovy.tools.RootLoader.oldFindClass(RootLoader.java:152)
      at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:124)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
      at java.security.Provider$Service.getImplClass(Provider.java:1262)
      at java.security.Provider$Service.newInstance(Provider.java:1220)
      at javax.crypto.Cipher.getInstance(DashoA13*..)
      at javax.crypto.Cipher.getInstance(DashoA13*..)
      at javax.crypto.Cipher$getInstance$0.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129)
      at CipherTest$_run_closure1.doCall(CipherTest.groovy:7)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:893)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151)
      at CipherTest$_run_closure1.doCall(CipherTest.groovy)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
      ... 7 more

        Activity

        blackdrag blackdrag made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Jochen Theodorou [ blackdrag ]
        Fix Version/s 1.7.11 [ 17244 ]
        Fix Version/s 1.8.2 [ 17495 ]
        Fix Version/s 1.9-beta-2 [ 17494 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Sebastian Gozin
          • Votes:
            4 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: