compareIgnoreCase
을 사용하는 동안 NegativeArraySizeException
/'NullPointerException'(Java 7 JRE에서 실행)이 표시됩니다.java 문자열이 이상한 동작을합니다.
Caused by: java.lang.NegativeArraySizeException
at java.lang.String.toCharArray(String.java:2748)
at sun.text.normalizer.NormalizerImpl.canonicalDecomposeWithSingleQuotation(NormalizerImpl.java:2506)
at java.text.RBTableBuilder.build(RBTableBuilder.java:107)
at java.text.RBCollationTables.<init>(RBCollationTables.java:83)
at java.text.RuleBasedCollator.<init>(RuleBasedCollator.java:300)
at java.text.RuleBasedCollator.<init>(RuleBasedCollator.java:281)
at java.text.Collator.getInstance(Collator.java:276)
및
Caused by: java.lang.NullPointerException
at java.lang.String.length(String.java:623)
at java.text.RBTableBuilder.build(RBTableBuilder.java:84)
at java.text.RBCollationTables.<init>(RBCollationTables.java:83)
at java.text.RuleBasedCollator.<init>(RuleBasedCollator.java:300)
at java.text.RuleBasedCollator.<init>(RuleBasedCollator.java:281)
at java.text.Collator.getInstance(Collator.java:276)
이들은 String.compareIgnoreCase 및 경우, String.equalsIgnoreCase
에서 일어날 것 같다샘플 코드 :
public static int compareIgnoreCase(Locale locale, String a, String b) {
if (a != null && a.length() == 0) {
a = null;
}
if (b != null && b.length() == 0) {
b = null;
}
//
if (a == b) {
return 0;
}
if (a == null) {
return -1;
}
if (b == null) {
return 1;
}
Collator collator = Collator.getInstance(locale);
collator.setStrength(Collator.SECONDARY);
return collator.compare(a, b);
}
에 의해 호출있어 :
,210NlsUtility.getDefaultLocale :
public static Locale getDefaultLocale() {
Locale locale = LocaleThreadLocal.get();
if (locale == null) {
locale = Locale.getDefault();
}
return locale;
}
그것은 JVM 충돌 다음에 돌아왔다 문제가 나타납니다. 나는이 문제를 해결하는 방법을 잘 모르겠어요 :
당신은 경우는, Collator.getInstance (로케일)을 호출하기 전에 당신에게 로케일을 확인해야#
# 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
#
코드의 버그로 인해 예외가 발생합니다 (즉, IMHO 자체 설명 및 명확함). 이유를 찾을 수없는 경우 문제를 재현하는 최소한의 코드 스냅 샷을 게시하십시오. – AlexR
* 언젠가는 자바 문자열이 이상한 예외를 던지면서 제대로 작동하지 않는 것처럼 보입니다. * 왜 그렇게 이상한가요? 실수는 인간입니다. 예외 메시지를 항상 확인하고 웹에서 검색 할 수도 있습니다. 대부분의 경우 SO 또는 문서에 대한 관련 링크가 바로 있습니다. –
에 의해 발생 : java.lang.NegativeArraySizeException, about about – Abdelhak