2016-08-17 6 views
-5

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); 
    } 

에 의해 호출있어 :

,210

NlsUtility.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 
# 
+0

코드의 버그로 인해 예외가 발생합니다 (즉, IMHO 자체 설명 및 명확함). 이유를 찾을 수없는 경우 문제를 재현하는 최소한의 코드 스냅 샷을 게시하십시오. – AlexR

+0

* 언젠가는 자바 문자열이 이상한 예외를 던지면서 제대로 작동하지 않는 것처럼 보입니다. * 왜 그렇게 이상한가요? 실수는 인간입니다. 예외 메시지를 항상 확인하고 웹에서 검색 할 수도 있습니다. 대부분의 경우 SO 또는 문서에 대한 관련 링크가 바로 있습니다. –

+0

에 의해 발생 : java.lang.NegativeArraySizeException, about about – Abdelhak

답변

0

... 당신 compareIgnoreCase 예외 (Nullpointer)를 제기하지만, 나는이 수표 나 아마는, Collator.getInstance() 동안 코드 오류로 인해 becuase 당신이 응용 프로그램을 디버깅하는 것이 좋습니다 이 버그는 JVM segfault를 만들고 있습니다. 비슷한 문제가있는 경우 How do I debug Segfaults occurring in the JVM when it runs my code?을 볼 수 있습니다.

0

;

유효하지 않은 길이() 또는 유효한 로캘로 null인지 확인하십시오. 애플리케이션 디버깅을 시도하십시오. 이것은 당신에게 어떤 일이 일어나고 있는지에 대한 조언을 줄 것입니다.

분명히 나타나는

+0

로캘은 Locale.forLanguageTa g ("nl-BE") 을 사용하여 설정됩니다. 메서드 호출 바로 전에 Null 검사가 있습니다. 로캘이 null 인 경우 Locale.getDefault를 사용합니다. 편집 : 성공적으로 인스턴스화 된 Locale 객체가 "길이가 유효하지 않은"이유는 확실하지 않습니다. –

+0

null 값으로 compareIgnoreCase 래치 오류가 발생했습니다. – crm86

+0

일부 정보를 제공 할 수있는 로그가 있습니까? 너를 돕기 위해? – crm86

관련 문제