Automated merge with http://hg.netbeans.org/core-main
authorffjre@netbeans.org
Tue, 07 Apr 2009 00:37:21 +0400
changeset 52992a0f73a01c3
parent 528 cf69b3714944
parent 527 e3fa2fb1fb1c
child 530 36fcbe493ff7
Automated merge with http://hg.netbeans.org/core-main
     1.1 --- a/openide.util/src/org/openide/util/Exceptions.java	Mon Apr 06 14:24:49 2009 -0400
     1.2 +++ b/openide.util/src/org/openide/util/Exceptions.java	Tue Apr 07 00:37:21 2009 +0400
     1.3 @@ -215,20 +215,25 @@
     1.4              }
     1.5              if (t.getCause() == null) {
     1.6                  if (create) {
     1.7 +                    IllegalStateException x = null;
     1.8                      try {
     1.9                          t.initCause(new AnnException());
    1.10 -                    } catch (IllegalStateException x) {
    1.11 -                        AnnException ann = extras.get(t);
    1.12 -                        if (ann == null) {
    1.13 -                            ann = new AnnException(t.getMessage());
    1.14 -                            ann.initCause(t);
    1.15 -                            LOG.log(Level.FINE, "getCause was null yet initCause failed for " + t, x);
    1.16 -                            extras.put(t, ann);
    1.17 +                        AnnException ann = (AnnException)t.getCause();
    1.18 +                        if (ann != null) {
    1.19 +                            return ann;
    1.20                          }
    1.21 -                        return ann;
    1.22 +                    } catch (IllegalStateException ex) {
    1.23 +                        x = ex;
    1.24                      }
    1.25 +                    AnnException ann = extras.get(t);
    1.26 +                    if (ann == null) {
    1.27 +                        ann = new AnnException(t.getMessage());
    1.28 +                        ann.initCause(t);
    1.29 +                        LOG.log(Level.FINE, "getCause was null yet initCause failed for " + t, x);
    1.30 +                        extras.put(t, ann);
    1.31 +                    }
    1.32 +                    return ann;
    1.33                  }
    1.34 -                return (AnnException)t.getCause();
    1.35              }
    1.36              return findOrCreate(t.getCause(), create);
    1.37          }
     2.1 --- a/openide.util/test/unit/src/org/openide/util/ExceptionsTest.java	Mon Apr 06 14:24:49 2009 -0400
     2.2 +++ b/openide.util/test/unit/src/org/openide/util/ExceptionsTest.java	Tue Apr 07 00:37:21 2009 +0400
     2.3 @@ -150,5 +150,31 @@
     2.4  
     2.5          assertCleanStackTrace(e);
     2.6      }
     2.7 +
     2.8 +    public void testAttachLocalizedMessageForWeirdException() {
     2.9 +        class WeirdEx extends Exception {
    2.10 +            public WeirdEx(String message) {
    2.11 +                super(message);
    2.12 +            }
    2.13 +
    2.14 +            @Override
    2.15 +            public Throwable getCause() {
    2.16 +                return null;
    2.17 +            }
    2.18 +        }
    2.19 +
    2.20 +        Exception e = new WeirdEx("Help");
    2.21 +        String msg = "me please";
    2.22 +
    2.23 +        Exception expResult = e;
    2.24 +        Exception result = Exceptions.attachMessage(e, msg);
    2.25 +        assertEquals(expResult, result);
    2.26 +
    2.27 +        String fnd = Exceptions.findLocalizedMessage(e);
    2.28 +
    2.29 +        assertEquals("No localized msg found", null, fnd);
    2.30 +
    2.31 +        assertCleanStackTrace(e);
    2.32 +    }
    2.33      
    2.34  }