Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java字符串与collator的奇数行为_Java_String - Fatal编程技术网

java字符串与collator的奇数行为

java字符串与collator的奇数行为,java,string,Java,String,在使用compareIgnoreCase时,我得到了NegativeArraySizeException/'NullPointerException'(在Java 7 JRE中运行) 被称为: public static int compareIgnoreCase(String a, String b) { return compareIgnoreCase(NlsUtility.getDefaultLocale(), a, b); } NlsUtility.getDefault

在使用
compareIgnoreCase
时,我得到了
NegativeArraySizeException
/'NullPointerException'(在Java 7 JRE中运行)

被称为:

  public static int compareIgnoreCase(String a, String b) {
    return compareIgnoreCase(NlsUtility.getDefaultLocale(), a, b);
  }
NlsUtility.getDefaultLocale:

  public static Locale getDefaultLocale() {
    Locale locale = LocaleThreadLocal.get();
    if (locale == null) {
      locale = Locale.getDefault();
    }
    return locale;
  }
问题似乎又出现了,接着是JVM崩溃。我不知道如何解决这个问题:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f1dabb9d4f0, pid=4290, tid=139765228910336
#
# JRE version: Java(TM) SE Runtime Environment (7.0_80-b15) (build 1.7.0_80-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.80-b11 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0x7ee4f0]  nmethod::can_unload(BoolObjectClosure*, OopClosure*, oopDesc**, bool)+0x70
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /tmp/hs_err_pid4290.log
Compiled method (c2) 191914528 4305  s!         java.text.Collator::getInstance (157 bytes)
 total in heap  [0x00007f1da19f7f90,0x00007f1da19fa8f8] = 10600
 relocation     [0x00007f1da19f80b0,0x00007f1da19f8290] = 480
 constants      [0x00007f1da19f82a0,0x00007f1da19f82c0] = 32
 main code      [0x00007f1da19f82c0,0x00007f1da19f9980] = 5824
 stub code      [0x00007f1da19f9980,0x00007f1da19f9a40] = 192
 oops           [0x00007f1da19f9a40,0x00007f1da19f9b30] = 240
 scopes data    [0x00007f1da19f9b30,0x00007f1da19fa3d0] = 2208
 scopes pcs     [0x00007f1da19fa3d0,0x00007f1da19fa690] = 704
 dependencies   [0x00007f1da19fa690,0x00007f1da19fa6a8] = 24
 handler table  [0x00007f1da19fa6a8,0x00007f1da19fa8d0] = 552
 nul chk table  [0x00007f1da19fa8d0,0x00007f1da19fa8f8] = 40
Compiled method (c2) 191914528 4305  s!         java.text.Collator::getInstance (157 bytes)
 total in heap  [0x00007f1da19f7f90,0x00007f1da19fa8f8] = 10600
 relocation     [0x00007f1da19f80b0,0x00007f1da19f8290] = 480
 constants      [0x00007f1da19f82a0,0x00007f1da19f82c0] = 32
 main code      [0x00007f1da19f82c0,0x00007f1da19f9980] = 5824
 stub code      [0x00007f1da19f9980,0x00007f1da19f9a40] = 192
 oops           [0x00007f1da19f9a40,0x00007f1da19f9b30] = 240
 scopes data    [0x00007f1da19f9b30,0x00007f1da19fa3d0] = 2208
 scopes pcs     [0x00007f1da19fa3d0,0x00007f1da19fa690] = 704
 dependencies   [0x00007f1da19fa690,0x00007f1da19fa6a8] = 24
 handler table  [0x00007f1da19fa6a8,0x00007f1da19fa8d0] = 552
 nul chk table  [0x00007f1da19fa8d0,0x00007f1da19fa8f8] = 40
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

在调用Collator.getInstance(locale)之前,必须检查您的locale

检查它是否为null,长度()或区域设置无效。尝试调试您的应用程序。这将给你一些关于那里发生的事情的建议


显然,您的CompareIgnorCase会引发异常(Nullpointer),但我建议调试您的应用程序,因为这是由于您的检查中的代码失败,或者可能是在Collator.getInstance()…

过程中,此错误似乎导致JVM出现错误。您可以查看是否有类似的问题。

您会因为代码中的错误而出现异常(这是可以自我解释和清楚的)。如果您自己找不到原因,请尝试发布再现问题的最小代码快照。您要为
locale
变量传递什么值?我认为如果
locale
变量为null或不是有效的区域设置,就会发生此错误。我无法使用此代码复制错误,并传递您指定的区域设置。你确定你通过的是那个区域而不是其他区域吗?也许您可以在调用
Collator.getInstance
之前使用调试器检查
locale
的值。好的,我刚刚阅读了您的最后一条评论。我想知道附加调试器是否会影响语言环境。您可以尝试在没有调试器的情况下运行,但将行
System.out.println(LocaleData.getCollationData(locale.getString)(“Rule”)Collator.getInstance
之前的code>。如果这显示为null,那么您的Java运行时中的区域设置数据就有问题,您可能应该转移到以后的Java构建中。也许缓存被破坏了。在这一点上进行验尸是不可能的。对不起,我想这里的任何人都帮不了你。语言环境是使用locale.forLanguageTa设置的‌​在方法调用之前,有一个空检查。如果区域设置为null,它将使用locale.getDefault编辑:我不确定成功实例化的区域设置对象如何具有“无效长度”您是否有日志可以为我们提供一些信息以帮助您?空指针实际上是在java.lang.String.length(String.java:623)处提出的,我想它是从java.text.Collator.getInstance(Collator.java:276)开始的. 我正在读有关forLanguageTa的书‌g(“…”)并且可能您的区域设置实例对于某些奇怪的东西不是格式良好的。很抱歉,我无法提取更多信息。应用程序中只有三种语言环境:nl BE、fr BE、Locale.getDefault。我不知道这三个人有什么奇怪的。它们是有效的区域设置。在代码中没有任何干预的情况下,异常停止发生。
  public static int compareIgnoreCase(String a, String b) {
    return compareIgnoreCase(NlsUtility.getDefaultLocale(), a, b);
  }
  public static Locale getDefaultLocale() {
    Locale locale = LocaleThreadLocal.get();
    if (locale == null) {
      locale = Locale.getDefault();
    }
    return locale;
  }
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f1dabb9d4f0, pid=4290, tid=139765228910336
#
# JRE version: Java(TM) SE Runtime Environment (7.0_80-b15) (build 1.7.0_80-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.80-b11 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0x7ee4f0]  nmethod::can_unload(BoolObjectClosure*, OopClosure*, oopDesc**, bool)+0x70
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /tmp/hs_err_pid4290.log
Compiled method (c2) 191914528 4305  s!         java.text.Collator::getInstance (157 bytes)
 total in heap  [0x00007f1da19f7f90,0x00007f1da19fa8f8] = 10600
 relocation     [0x00007f1da19f80b0,0x00007f1da19f8290] = 480
 constants      [0x00007f1da19f82a0,0x00007f1da19f82c0] = 32
 main code      [0x00007f1da19f82c0,0x00007f1da19f9980] = 5824
 stub code      [0x00007f1da19f9980,0x00007f1da19f9a40] = 192
 oops           [0x00007f1da19f9a40,0x00007f1da19f9b30] = 240
 scopes data    [0x00007f1da19f9b30,0x00007f1da19fa3d0] = 2208
 scopes pcs     [0x00007f1da19fa3d0,0x00007f1da19fa690] = 704
 dependencies   [0x00007f1da19fa690,0x00007f1da19fa6a8] = 24
 handler table  [0x00007f1da19fa6a8,0x00007f1da19fa8d0] = 552
 nul chk table  [0x00007f1da19fa8d0,0x00007f1da19fa8f8] = 40
Compiled method (c2) 191914528 4305  s!         java.text.Collator::getInstance (157 bytes)
 total in heap  [0x00007f1da19f7f90,0x00007f1da19fa8f8] = 10600
 relocation     [0x00007f1da19f80b0,0x00007f1da19f8290] = 480
 constants      [0x00007f1da19f82a0,0x00007f1da19f82c0] = 32
 main code      [0x00007f1da19f82c0,0x00007f1da19f9980] = 5824
 stub code      [0x00007f1da19f9980,0x00007f1da19f9a40] = 192
 oops           [0x00007f1da19f9a40,0x00007f1da19f9b30] = 240
 scopes data    [0x00007f1da19f9b30,0x00007f1da19fa3d0] = 2208
 scopes pcs     [0x00007f1da19fa3d0,0x00007f1da19fa690] = 704
 dependencies   [0x00007f1da19fa690,0x00007f1da19fa6a8] = 24
 handler table  [0x00007f1da19fa6a8,0x00007f1da19fa8d0] = 552
 nul chk table  [0x00007f1da19fa8d0,0x00007f1da19fa8f8] = 40
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#