Fix SOE when calling Throwable.getCause()

Fix https://github.com/konsoletyper/teavm/issues/249
This commit is contained in:
Alexey Andreev 2017-03-27 22:27:59 +03:00
parent d49354bdac
commit 4847731328
2 changed files with 37 additions and 6 deletions

View File

@ -21,10 +21,6 @@ import org.teavm.interop.Remove;
import org.teavm.interop.Rename;
import org.teavm.interop.Superclass;
/**
*
* @author Alexey Andreev
*/
@Superclass("java.lang.Object")
public class TThrowable extends RuntimeException {
private static final long serialVersionUID = 2026791432677149320L;
@ -115,8 +111,11 @@ public class TThrowable extends RuntimeException {
return TString.wrap(getMessage());
}
@Override
public TThrowable getCause() {
@Remove
public native TThrowable getCause();
@Rename("getCause")
public TThrowable getCause0() {
return cause != this ? cause : null;
}

View File

@ -0,0 +1,32 @@
/*
* Copyright 2017 Alexey Andreev.
*
* 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 org.teavm.classlib.java.lang;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.teavm.junit.TeaVMTestRunner;
@RunWith(TeaVMTestRunner.class)
public class ThrowableTest {
@Test
public void causeWorks() {
RuntimeException e = new RuntimeException("fail", new RuntimeException("OK"));
assertTrue(e.getCause() instanceof RuntimeException);
assertEquals("OK", e.getCause().getMessage());
}
}