Bug 53440

Summary: SSL connection leads to ArrayStoreException on JDK 6 with some KeyManagerFactory SPI
Product: JMeter - Now in Github Reporter: Patrick Heusser <patrick.heusser>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: normal CC: p.mouawad
Priority: P2    
Version: 2.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Patrick Heusser 2012-06-20 09:40:24 UTC
On Windows with JDK 6 when establishing a connection over SSL i got the stack posted below with the array ArrayStoreException... This is reproducable and does NOT happen on a JDK 5 installation. 

This happens just at runtime. The code can be compiled with JDK 5 and JDK 6... 

Exact java version that produces the error:
> java -version
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) Client VM (build 20.5-b03, mixed mode, sharing)

workaround:
Use a JDK 1.5



STACK-TRACE
-----------
java.lang.ArrayStoreException: org.apache.jmeter.util.JsseSSLManager$WrappedX509KeyManager
	at org.apache.jmeter.util.JsseSSLManager.createContext(JsseSSLManager.java:241)
	at org.apache.jmeter.util.JsseSSLManager.getContext(JsseSSLManager.java:198)
	at org.apache.jmeter.util.HttpSSLProtocolSocketFactory.getSSLSocketFactory(HttpSSLProtocolSocketFactory.java:103)
	at org.apache.jmeter.util.HttpSSLProtocolSocketFactory.createSocket(HttpSSLProtocolSocketFactory.java:147)
	at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
	at org.apache.jmeter.protocol.http.sampler.HTTPHC3Impl.sample(HTTPHC3Impl.java:249)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1060)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1049)
	at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:442)
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:271)
	at java.lang.Thread.run(Unknown Source)


Best regards,
patrick
Comment 1 Sebb 2012-06-22 01:01:21 UTC
The code in question is:

KeyManager[] managers = managerFactory.getKeyManagers();
...
for (int i = 0; i < managers.length; i++) {
    if (managers[i] instanceof X509KeyManager) {
        X509KeyManager manager = (X509KeyManager) managers[i];
        managers[i] = new WrappedX509KeyManager(manager, keys); // line 241
    }
}

Now WrappedX509KeyManager implements X509KeyManager which extends KeyManager.
I don't see how the code would even compile unless this were true, so an ArrayStoreException should be impossible.

I've tried with java.version=1.6.0_31 on Windows and it works fine for me.

Please can you provide the simplest possible test script that shows the problem, along with log files for Java 1.5 and 1.6?
Comment 2 Patrick Heusser 2012-06-22 06:43:15 UTC
hi

thx for looking at it.

i had a quick look at the code too. for both java API 1.5 and 1.6 the hierarchy is the same and it compiles with both, but does fail at runtime. so it must be obviously related to the JDK and NOT Jmeter itself. it would be nice, if Jmeter could work "around" it. the sampler with the request fails completely, may be a simple try/catch helps.

our server under test asks for a client certificate, even though it's not required in the end. my guess is this causes the failure. 

regards,
Comment 3 Sebb 2012-06-22 14:23:21 UTC
We really need to be able to reproduce the issue.

Can you provide a simple test case that exhibits the problem, together with any changes you made to jmeter.properties or system.properties?

Also, it would be helpful to have the jmeter logs for both runs.

If necessary, feel free to replace the names of servers etc with place-holders.

Also, just in case it is a specific issue with Java 1.6.0_30, can you try with the current release, i.e.  1.6.0_33?
Comment 4 Sebb 2012-06-22 16:53:59 UTC
I've managed now to set up a test with Tomcat. 
It uses clientAuth="true" and requires a certificate.

I was able to connect to Tomcat with Firefox and with JMeter; no problems were encountered with 1.5.0_22, 1.6.0_33, 1.7.0_05.

This is looking like a problem with your Java 6 installation, i.e. the bug should be closed as "WORKSFORME" unless you can provide a test case that can be repeated by others.
Comment 5 Philippe Mouawad 2012-06-23 21:46:29 UTC
Hello Sebb,
I think issue is possible because we don't know the real type of array allocated.

Take the following snippet:
    public static void main(String[] args) {
        Number[] t = new Integer[5];
        t[0] = new Long(123);
    }

Long is a Number but it provokes an ArrayStoreException cause allocated array elements if not a Long array.
Comment 6 Philippe Mouawad 2012-06-23 21:51:44 UTC
To be clearer it can happen if SPI does not allocate a KeyManager array but a subclass.
Comment 7 Philippe Mouawad 2012-06-23 22:07:55 UTC
Date: Sat Jun 23 22:06:21 2012
New Revision: 1353205

URL: http://svn.apache.org/viewvc?rev=1353205&view=rev
Log:
Bug 53440 - SSL connection leads to ArrayStoreException on JDK 6 with some KeyManagerFactory SPI
Bugzilla Id: 53440

Modified:
   jmeter/trunk/src/core/org/apache/jmeter/util/JsseSSLManager.java
   jmeter/trunk/xdocs/changes.xml
Comment 8 Philippe Mouawad 2012-06-23 22:16:00 UTC
Hello M. Heusser,
It would be helpful if you could confirm that issue is fixed for you using a nightly build that will be generated within hours.
- http://jmeter.apache.org/nightly.html
As I was not able to reproduce it on my configuration.
Thank you
Regards
Philippe
Comment 9 Patrick Heusser 2012-06-26 17:39:34 UTC
hi jmeter team

i did some more testing with different JVM versions. i found, that my observation is very specific to the version i used (see bug submission). i did tests with the two version listed below, both work OK! 

still, i gonna try your nightly fix. sorry to be a bit slow on that, i'm in a rather restricted environment where it's a bit hard to test such stuff...

one note: i'm extremely impressed by the work and commitment that you guys do. respect and thanks a lot! JMeter is a cool tool :-)

JVM WORKS OK: 
D:\Data\Rad\shared\programs\Java\jre6_32bit\bin>java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03)
Java HotSpot(TM) Client VM (build 20.8-b03, mixed mode, sharing)
 
JVM WORKS OK: 
D:\Data\Rad\shared\programs\Java\jdk1.7.0_05_32bit\bin>java -version
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) Client VM (build 23.1-b03, mixed mode)

cheers,
patrick
Comment 10 Patrick Heusser 2012-06-27 05:58:44 UTC
hi guys

i tested the nightly build r1353803 this morning. 

=> it was a full success! the exception has gone.

thanks a lot,
patrick
Comment 11 The ASF infrastructure team 2022-09-24 20:37:50 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2847