public static String createString ( char [ ] charBuf ) { if ( ! enabled ) { return createStringFallback ( charBuf ) ; } String str = new String ( ) ; try { // try to prevent possible final field setting execution reordering in JIT // (JSR-133/JMM, "9.1.1 Post-Construction Modification of Final Fields") // it was a bit unclear for me if this could ever happen in a single thread synchronized ( str ) { valueField . set ( str , charBuf ) ; countField . set ( str , charBuf . length ) ; } synchronized ( str ) { // safety check, just to be sure that setting the final fields went ok if ( str . length ( ) != charBuf . length ) { throw new IllegalStateException ( "Fast java.lang.String construction failed." ) ; } } } catch ( Exception e ) { handleError ( e ) ; str = createStringFallback ( charBuf ) ; } return str ; }
creates a new java . lang . String by setting the char array directly to the String instance with reflection .