This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 31254
Collapse All | Expand All

(-)core/src/org/netbeans/core/NbErrorManager.java (-9 / +27 lines)
Lines 530-540 Link Here
530
530
531
        /** @return message */
531
        /** @return message */
532
        String getMessage () {
532
        String getMessage () {
533
            String m = t.getMessage();
534
            if (m != null) {
535
                return m;
536
            }
533
            return (String)find (1);
537
            return (String)find (1);
534
        }
538
        }
535
539
536
        /** @return localized message */
540
        /** @return localized message */
537
        String getLocalizedMessage () {
541
        String getLocalizedMessage () {
542
            String m = t.getLocalizedMessage();
543
            if (m != null && !m.equals(t.getMessage())) {
544
                return m;
545
            }
538
            if (arrAll == null) {
546
            if (arrAll == null) {
539
                // arrAll not filled --> use the old non recursive variant
547
                // arrAll not filled --> use the old non recursive variant
540
                return (String)find(2);
548
                return (String)find(2);
Lines 545-560 Link Here
545
                    return s;
553
                    return s;
546
                }
554
                }
547
            }
555
            }
548
            return t.getLocalizedMessage();
556
            return m;
549
        }
557
        }
550
	
558
	
551
        boolean isLocalized() {
559
        boolean isLocalized() {
552
	    if (find(2, false) == null) {
560
            String m = t.getLocalizedMessage();
553
		String locMsg = getLocalizedMessage();
561
            if (m != null && !m.equals(t.getMessage())) {
554
		return locMsg != null && !locMsg.equals(getMessage());
562
                return true;
555
	    } 
563
            }
556
	    else
564
            if (arrAll == null) {
557
		return true;	
565
                // arrAll not filled --> use the old non recursive variant
566
                return (String)find(2) != null;
567
            }
568
            for (int i = 0; i < arrAll.length; i++) {
569
                String s = arrAll[i].getLocalizedMessage ();
570
                if (s != null) {
571
                    return true;
572
                }
573
            }
574
            return false;
558
	}
575
	}
559
576
560
        /** @return class name of the exception */
577
        /** @return class name of the exception */
Lines 568-575 Link Here
568
                return severity;
585
                return severity;
569
            }
586
            }
570
587
571
            for (int i = 0; i < arr.length; i++) {
588
            Annotation[] anns = (arrAll != null) ? arrAll : arr;
572
                int s = arr[i].getSeverity ();
589
            for (int i = 0; i < anns.length; i++) {
590
                int s = anns[i].getSeverity ();
573
                if (s > severity) {
591
                if (s > severity) {
574
                    severity = s;
592
                    severity = s;
575
                }
593
                }
(-)core/test/unit/src/org/netbeans/core/NbErrorManagerTest.java (+66 lines)
Lines 191-194 Link Here
191
        // could do more here...
191
        // could do more here...
192
    }
192
    }
193
    
193
    
194
    /**
195
     * Check that UNKNOWN works.
196
     * @see "#30947"
197
     */
198
    public void testUnknownSeverity() throws Exception {
199
        
200
        // Simple exception is EXCEPTION.
201
        Throwable t = new IOException("unloc msg");
202
        NbErrorManager.Exc x = err.createExc(t, ErrorManager.UNKNOWN);
203
        assertEquals(ErrorManager.EXCEPTION, x.getSeverity());
204
        assertEquals("unloc msg", x.getMessage());
205
        assertEquals("unloc msg", x.getLocalizedMessage());
206
        assertTrue(!x.isLocalized());
207
        
208
        // Same when there is unloc debug info attached.
209
        t = new IOException("unloc msg");
210
        err.annotate(t, ErrorManager.UNKNOWN, "some debug info", null, null, null);
211
        x = err.createExc(t, ErrorManager.UNKNOWN);
212
        assertEquals(ErrorManager.EXCEPTION, x.getSeverity());
213
        assertEquals("unloc msg", x.getMessage());
214
        assertEquals("unloc msg", x.getLocalizedMessage());
215
        assertTrue(!x.isLocalized());
216
        
217
        // Nested exceptions don't necessarily change anything severity-wise.
218
        t = new IOException("unloc msg");
219
        Throwable t2 = new IOException("unloc msg #2");
220
        err.annotate(t, ErrorManager.UNKNOWN, null, null, t2, null);
221
        x = err.createExc(t, ErrorManager.UNKNOWN);
222
        assertEquals(ErrorManager.EXCEPTION, x.getSeverity());
223
        assertEquals("unloc msg", x.getMessage());
224
        assertEquals("unloc msg", x.getLocalizedMessage());
225
        assertTrue(!x.isLocalized());
226
        
227
        // But annotations at a particular severity level (usually localized) do
228
        // set the severity for the exception.
229
        t = new IOException("unloc msg");
230
        err.annotate(t, ErrorManager.USER, null, "loc msg", null, null);
231
        x = err.createExc(t, ErrorManager.UNKNOWN);
232
        assertEquals(ErrorManager.USER, x.getSeverity());
233
        assertEquals("unloc msg", x.getMessage());
234
        assertEquals("loc msg", x.getLocalizedMessage());
235
        assertTrue(x.isLocalized());
236
        
237
        // And that works even if you are just rethrowing someone else's exception.
238
        t = new IOException("unloc msg");
239
        t2 = new IOException("unloc msg #2");
240
        err.annotate(t2, ErrorManager.USER, null, "loc msg", null, null);
241
        err.annotate(t, ErrorManager.UNKNOWN, null, null, t2, null);
242
        x = err.createExc(t, ErrorManager.UNKNOWN);
243
        assertEquals(ErrorManager.USER, x.getSeverity());
244
        assertEquals("unloc msg", x.getMessage());
245
        assertEquals("loc msg", x.getLocalizedMessage());
246
        assertTrue(x.isLocalized());
247
        // Almost the same test to mimic #31254:
248
        t2 = new IOException("loc msg");
249
        err.annotate(t2, ErrorManager.USER, null, "loc msg", null, null);
250
        t = new IOException("loc msg");
251
        err.annotate(t, ErrorManager.USER, null, null, t2, null);
252
        x = err.createExc(t, ErrorManager.UNKNOWN);
253
        assertEquals(ErrorManager.USER, x.getSeverity());
254
        assertEquals("loc msg", x.getMessage());
255
        assertEquals("loc msg", x.getLocalizedMessage());
256
        assertTrue(x.isLocalized());
257
        
258
    }
259
    
194
}
260
}

Return to bug 31254