Debian Codegraph @

src/com/bulenkov/iconloader/util/StringFactory.java

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Copyright 2000-2014 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.bulenkov.iconloader.util;
18
•19 //import sun.reflect.ConstructorAccessor;
20
21 import java.lang.reflect.Constructor;
22 import java.lang.reflect.Method;
23
24 /**
25 * @author Konstantin Bulenkov
26 */
27 public class StringFactory {
28 // String(char[], boolean). Works since JDK1.7, earlier JDKs have too slow reflection anyway
•29 //private static final ConstructorAccessor ourConstructorAccessor;
30
31 static {
•32 /*
33 ConstructorAccessor constructorAccessor = null;
34 try {
35 Constructor<String> newC = String.class.getDeclaredConstructor(char[].class, boolean.class);
36 newC.setAccessible(true);
37 // it is faster to invoke constructor via sun.reflect.ConstructorAccessor; it avoids AccessibleObject.checkAccess()
38 Method accessor = Constructor.class.getDeclaredMethod("acquireConstructorAccessor");
39 accessor.setAccessible(true);
40 constructorAccessor = (ConstructorAccessor) accessor.invoke(newC);
41 } catch (Exception ignored) {
42 }
43 ourConstructorAccessor = constructorAccessor;
•44 */
45 }
46
47
48 /**
49 * @return new instance of String which backed by 'chars' array.
50 * <p/>
51 * CAUTION. EXTREMELY DANGEROUS.
52 * DO NOT USE THIS METHOD UNLESS YOU ARE TOO DESPERATE
53 */
54 public static String createShared(char[] chars) {
•55 /*
56 if (ourConstructorAccessor != null) {
57 try {
58 return (String) ourConstructorAccessor.newInstance(new Object[]{chars, Boolean.TRUE});
59 } catch (Exception e) {
60 throw new RuntimeException(e);
61 }
62 }
•63 */
64 return new String(chars);
65 }
66 }
67