Revision: 17309
          http://sourceforge.net/p/gate/code/17309
Author:   valyt
Date:     2014-02-14 15:40:58 +0000 (Fri, 14 Feb 2014)
Log Message:
-----------
Copied fix from 5.0 branch: charset encoders / decoders are not thread safe, so 
the fields should not be static. 

Modified Paths:
--------------
    mimir/trunk/mimir-core/src/gate/mimir/index/mg4j/TokenIndexBuilder.java

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/index/mg4j/TokenIndexBuilder.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/index/mg4j/TokenIndexBuilder.java     
2014-02-14 15:33:24 UTC (rev 17308)
+++ mimir/trunk/mimir-core/src/gate/mimir/index/mg4j/TokenIndexBuilder.java     
2014-02-14 15:40:58 UTC (rev 17309)
@@ -56,20 +56,10 @@
   
   public static final String TOKEN_INDEX_BASENAME = "token";
   
-  protected static final CharsetEncoder UTF8_CHARSET_ENCODER = 
Charset.forName("UTF-8").newEncoder();
+  protected final CharsetEncoder utf8CharsetEncoder = 
Charset.forName("UTF-8").newEncoder();
   
-  protected static final CharsetDecoder UTF8_CHARSET_DECODER = 
Charset.forName("UTF-8").newDecoder();
+  protected final CharsetDecoder utf8CharsetDecoder = 
Charset.forName("UTF-8").newDecoder();
   
-  static {
-    try {
-      UTF8_CHARSET_ENCODER.replaceWith("[?]".getBytes("UTF-8"));
-      UTF8_CHARSET_ENCODER.onMalformedInput(CodingErrorAction.REPLACE);
-      UTF8_CHARSET_ENCODER.onUnmappableCharacter(CodingErrorAction.REPLACE);
-    } catch(UnsupportedEncodingException e) {
-      // this should never happen
-      throw new RuntimeException("UTF-8 not supported");
-    }
-  }
   /**
    * A zip collection builder used to build a zip of the collection
    * if this has been requested.
@@ -148,7 +138,14 @@
       logger.info("Creating zipped collection for field \"" + featureName + 
"\"");
       collectionWriter = new DocumentCollectionWriter(indexer.getIndexDir());
     }
-    
+    try {
+      utf8CharsetEncoder.replaceWith("[?]".getBytes("UTF-8"));
+      utf8CharsetEncoder.onMalformedInput(CodingErrorAction.REPLACE);
+      utf8CharsetEncoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+    } catch(UnsupportedEncodingException e) {
+      // this should never happen
+      throw new RuntimeException("UTF-8 not supported");
+    }
   }
 
 
@@ -233,8 +230,8 @@
     // illegal strings will simply be rendered as "?"
     try {
       CharBuffer cb = CharBuffer.wrap(value);
-      ByteBuffer bb = UTF8_CHARSET_ENCODER.encode(cb);
-      cb = UTF8_CHARSET_DECODER.decode(bb);
+      ByteBuffer bb = utf8CharsetEncoder.encode(cb);
+      cb = utf8CharsetDecoder.decode(bb);
       value  = cb.toString();
     } catch(CharacterCodingException e) {
       // this should not happen

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to