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

Occasional ArrayIndexOutOfBoundsException due to SimpleDateFormat use #184

Closed
mdeeks opened this issue Feb 4, 2015 · 2 comments
Closed

Comments

@mdeeks
Copy link

mdeeks commented Feb 4, 2015

We're heavily using jolokia in our environment for monitoring purposes. Occasionally jolokia dies and returns 500s with the exception pasted below. I'm guessing it is due to the re-use of SimpleDateFormat in JolokiaHttpHandler. From the Javadocs: "Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally."

Once jolokia gets into this state it does not recover without restarting the process. Here is the exception I get when doing a GET /jolokia/version on one of the broken instances:

java.lang.ArrayIndexOutOfBoundsException: -2147483648
    at java.util.Calendar.getDisplayName(Calendar.java:2098)
    at java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:1125)
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:966)
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:936)
    at java.text.DateFormat.format(DateFormat.java:345)
    at org.jolokia.jvmagent.JolokiaHttpHandler.setHeaders(JolokiaHttpHandler.java:225)
    at org.jolokia.jvmagent.JolokiaHttpHandler.handle(JolokiaHttpHandler.java:139)
    at com.sun.net.httpserver.Filter.doFilter(Filter.java:79)
    at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
    at com.sun.net.httpserver.Filter.doFilter(Filter.java:82)
    at sun.net.httpserver.ServerImpl.handle(ServerImpl.java:675)
    at com.sun.net.httpserver.Filter.doFilter(Filter.java:79)
    at sun.net.httpserver.ServerImpl.run(ServerImpl.java:647)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
@rhuss
Copy link
Member

rhuss commented Mar 3, 2015

Thanks for the report, I will have a look at it. Probably on friday (sorry, busy right now ...)

@markus-meisterernst
Copy link

Hi Roland,

da ich die Sourcen gerade offen hatte ...:

Das SimpleDateFormat ist nicht ThreadSafe. Daher sollte es nicht als Instanzvariable gecached werden (sofern der Zugriff nicht synchronisiert ist).

daher, statt
headers.set("Date",rfc1123Format.format(cal.getTime()));
besser durch:
headers.set("Date",new SimpleDateFormat().format(cal.getTime()));
ersetzen.

Hope that helps.

Grüße,

Markus

Am 03.03.2015 um 14:42 schrieb Roland Huß notifications@github.com:

Thanks for the report, I will have a look at it. Probably on friday (sorry, busy right now ...)


Reply to this email directly or view it on GitHub.

@rhuss rhuss closed this as completed in bc08d4b Mar 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants