如何从Java中的String类设置DisableCopyinsbstring系统属性?

如何从Java中的String类设置DisableCopyinsbstring系统属性?,java,string,jvm,Java,String,Jvm,这是IBM/Websphere Java 1.8.64的字符串类的一个片段 /** * This is a System property to disable copying the String when offset is non-zero in {@link #substring(int)}} and {@link #substring(int, int)}} */ static boolean disableCopyInSubstring; 我想这样设

这是IBM/Websphere Java 1.8.64的字符串类的一个片段

    /**
    *  This is a System property to disable copying the String when offset is non-zero in {@link #substring(int)}} and {@link #substring(int, int)}}
    */
   static boolean disableCopyInSubstring;
我想这样设置属性

System.setProperty("java.lang.String.disableCopyInSubstring", "true");
但是,显然这不是设置它的正确方法,因为我正在调试String类,而该变量仍然显示
false

从我正在使用的String类中添加一个更大的代码段。这是IBM的WebSphereJava1.8.64。当我问起这个问题时,我原本以为我在使用Oracle的Java。下面是该变量及以上的代码片段

package java.lang;

/*
 * Licensed Materials - Property of IBM,
 *     Copyright IBM Corp. 1998, 2016  All Rights Reserved
 */

import java.io.Serializable;

import java.util.Locale;
import java.util.Comparator;
import java.io.UnsupportedEncodingException;

import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.Formatter;
import java.util.StringJoiner;
import java.util.Iterator;

import java.nio.charset.Charset;

/**
 * Strings are objects which represent immutable arrays of
 * characters.
 *
 * @author      OTI
 * @version     initial
 *
 * @see         StringBuffer
 */

public final class String implements Serializable, Comparable<String>, CharSequence {
    // DO NOT CHANGE OR MOVE THIS LINE
    // IT MUST BE THE FIRST THING IN THE INITIALIZATION
    private static final boolean STRING_OPT_IN_HW = StrCheckHWAvailable();
    private static final long serialVersionUID = -6849794470754667710L;

    /**
     * CaseInsensitiveComparator compares Strings ignoring the case of the
     * characters.
     */
    private static final class CaseInsensitiveComparator implements Comparator<String>, Serializable {
        static final long serialVersionUID = 8575799808933029326L;

        /**
         * Compare the two objects to determine
         * the relative ordering.
         *
         * @param       o1  an Object to compare
         * @param       o2  an Object to compare
         * @return      an int < 0 if object1 is less than object2,
         *              0 if they are equal, and > 0 if object1 is greater
         *
         * @exception   ClassCastException when objects are not the correct type
         */
        public int compare(String o1, String o2) {
            return o1.compareToIgnoreCase(o2);
        }
    };

    /**
     * A Comparator which compares Strings ignoring the case of the
     * characters.
     */
    public static final Comparator<String> CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator();
    private static final char[] ascii;
    private static String[] stringArray;
    private static final int stringArraySize = 10;
    private static class UnsafeHelpers {
        public final static long valueFieldOffset = getValueFieldOffset();
        static long getValueFieldOffset() {
            try { return sun.misc.Unsafe.getUnsafe().objectFieldOffset(String.class.getDeclaredField("value")); }
            catch (NoSuchFieldException e) { throw new RuntimeException(e); }
        }
    }
    /**
     *  This is a System property to enable copy in {@link #String(String)}}
     */
    static boolean enableCopy;

    /**
    *  This is a System property to disable copying the String when offset is non-zero in {@link #substring(int)}} and {@link #substring(int, int)}}
    */
   static boolean disableCopyInSubstring;
包java.lang;
/*
*许可材料-IBM的财产,
*版权所有IBM Corp.1998、2016保留所有权利
*/
导入java.io.Serializable;
导入java.util.Locale;
导入java.util.Comparator;
导入java.io.UnsupportedEncodingException;
导入java.util.regex.Pattern;
导入java.util.regex.PatternSyntaxException;
导入java.util.Formatter;
导入java.util.StringJoiner;
导入java.util.Iterator;
导入java.nio.charset.charset;
/**
*字符串是表示不可变数组的对象
*人物。
*
*@作者奥蒂
*@版本首字母
*
*@见StringBuffer
*/
公共final类字符串实现可序列化、可比较的CharSequence{
//不要改变或移动这条线
//它必须是初始化过程中的第一件事
私有静态最终布尔字符串_OPT_IN_HW=strcheckhwavaailable();
私有静态最终长serialVersionUID=-6849794470754667710L;
/**
*CaseInsensitiveComparator比较字符串,忽略
*人物。
*/
私有静态最终类CaseInsensitiveComparator实现了Comparator,可序列化{
静态最终长serialVersionUID=85757998089333029326L;
/**
*比较两个对象以确定
*相对顺序。
*
*@param o1要比较的对象
*@param o2是要比较的对象
*@如果object1小于object2,则返回int<0,
*如果它们相等,则为0;如果object1更大,则大于0
*
*@exception ClassCastException当对象类型不正确时
*/
公共整数比较(字符串o1、字符串o2){
返回o1.比较信号(o2);
}
};
/**
*一种比较字符串的比较器,忽略
*人物。
*/
public static final Comparator不区分大小写顺序=new caseinsensitiviecomparator();
私有静态最终字符[]ascii;
私有静态字符串[]字符串数组;
私有静态最终int-stringArraySize=10;
私有静态类非安全帮助程序{
公共最终静态长valueFieldOffset=getValueFieldOffset();
静态长getValueFieldOffset(){
请尝试{return sun.misc.Unsafe.getUnsafe().objectFieldOffset(String.class.getDeclaredField(“value”);}
catch(NoSuchFieldException e){抛出新的运行时异常(e);}
}
}
/**
*这是一个系统属性,用于在{@link#String(String)}中启用复制
*/
静态布尔使能复制;
/**
*这是一个系统属性,用于在{@link#substring(int)}和{@link#substring(int,int)}中的偏移量为非零时禁用复制字符串
*/
静态布尔禁用copyinsubsting;

要设置此系统属性,请在VM参数中设置以下属性

-Djava.lang.string.substring.nocopy=true

这就解决了问题。我只在IBM的Java实现中看到过这个问题。

您确定这个片段来自Java.lang.String吗?我在任何地方都找不到该属性。您使用的是OpenJDK还是其他供应商?我在1.8.77中找不到它。但是,由于您在源代码中找到了变量,所以请在更改它的源代码中进行搜索。起初我忽略了它,但我使用的是IBM的WebSphereJava1.8.64。