Skip to content

Commit

Permalink
AssertionError(Object) should only initCause if the object is a Throw…
Browse files Browse the repository at this point in the history
…able.

Bug: http://code.google.com/p/android/issues/detail?id=29378
Change-Id: I608901eed848ab496b8f54b784216b1362b561d2
  • Loading branch information
enh-google committed May 15, 2012
1 parent a9f768f commit f3d0739
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions luni/src/main/java/java/lang/AssertionError.java
Expand Up @@ -52,8 +52,10 @@ public AssertionError(String detailMessage, Throwable cause) {
* optionally the cause.
*/
public AssertionError(Object detailMessage) {
super(String.valueOf(detailMessage),
(detailMessage instanceof Throwable ? (Throwable) detailMessage : null));
super(String.valueOf(detailMessage));
if (detailMessage instanceof Throwable) {
initCause((Throwable) detailMessage);
}
}

/**
Expand Down
27 changes: 27 additions & 0 deletions luni/src/test/java/libcore/java/lang/AssertionErrorTest.java
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package libcore.java.lang;

import junit.framework.TestCase;

public final class AssertionErrorTest extends TestCase {
// http://code.google.com/p/android/issues/detail?id=29378
public void test_29378() throws Exception {
AssertionError ae = new AssertionError("hello");
ae.initCause(new Throwable());
}
}

0 comments on commit f3d0739

Please sign in to comment.