# REXML thread-safe?

**URL:** <https://www.ruby-forum.com/t/rexml-thread-safe/136742>\
**Category:** Ruby\
**Created:** [May 6, 2008, 1:30am UTC](https://www.ruby-forum.com/t/rexml-thread-safe/136742 "2008-05-06T01:30:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![2gatunek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/ecc23a/32.png) [@2gatunek](https://www.ruby-forum.com/u/2gatunek)\
**Post date:** [May 6, 2008, 1:30am UTC](https://www.ruby-forum.com/t/rexml-thread-safe/136742/1 "2008-05-06T01:30:42Z")

</div>

I am processing a lot of RSS using REXML and am hitting exceptions when  
running multiple threads (using JRuby). The exception always occurs when  
trying to access attributes on the same line of my code but at random  
times when I am running more than 1 thread. It does not happen when I  
run regular ruby, but green threads are probably less likely to switch  
context at the wrong time.

I noticed that in element.rb REXML has a class variable @@namespaces  
declared, however I could not find where it was used. The exception is  
always thrown in a section of code that deals with namespaces so I’m  
wondering if it is related.

I was hoping someone could let me know if REXML is supposed to be thread  
safe (one instance per thread)?

Thanks!

* * *

More details…

The exception is thrown on line 234 of rexml/element.rb in JRuby 1.1.1 :

Exception in thread “Ruby Thread16250988” java.lang.ClassCastException:  
org.jruby.RubyString  
at org.jruby.RubyNilInvoker$nil\_p\_method\_0\_0.call(Unknown  
Source)  
at  
org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:272)  
at  
ruby.jit.ruby.usr.local.jruby.lib.ruby.$1\_dot\_8.rexml.element.namespace1845016\_16032211. **file** (/usr/local/jruby/lib/ruby/1.8/rexml/element.rb:234)

---

<div class="post-metadata">

**Author:** ![2gatunek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/ecc23a/32.png) [@2gatunek](https://www.ruby-forum.com/u/2gatunek)\
**Post date:** [May 6, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/rexml-thread-safe/136742/2 "2008-05-06T20:08:55Z")

</div>

This was a bug with JRuby that is fixed in trunk.
