From 6f8866b42820efb83640abaae45c5f9dacb943c7 Mon Sep 17 00:00:00 2001 From: mikaelpeltier Date: Tue, 19 May 2015 17:52:55 +0200 Subject: Do not remove type of 'null' expression otherwise type is lost Bug: 19508222 Change-Id: I839ee69b454bf74dd93a6dffcb900c56fb68c3de (cherry picked from commit 731bf4c954500229d95fdacf424f7ccad6e5bdcf) --- .../tests/com/android/jack/cast/CastTests.java | 12 +++++++ .../android/jack/cast/explicit002/dx/Tests.java | 37 ++++++++++++++++++++++ .../jack/cast/explicit002/jack/Explicit002.java | 27 ++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 jack-tests/tests/com/android/jack/cast/explicit002/dx/Tests.java create mode 100644 jack-tests/tests/com/android/jack/cast/explicit002/jack/Explicit002.java (limited to 'jack-tests') diff --git a/jack-tests/tests/com/android/jack/cast/CastTests.java b/jack-tests/tests/com/android/jack/cast/CastTests.java index 6bccf9a..7401698 100644 --- a/jack-tests/tests/com/android/jack/cast/CastTests.java +++ b/jack-tests/tests/com/android/jack/cast/CastTests.java @@ -35,6 +35,10 @@ public class CastTests extends RuntimeTest { AbstractTestTools.getTestRootDir("com.android.jack.cast.explicit001"), "com.android.jack.cast.explicit001.dx.Tests"); + private RuntimeTestInfo EXPLICIT002 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.cast.explicit002"), + "com.android.jack.cast.explicit002.dx.Tests"); + private RuntimeTestInfo IMPLICIT001 = new RuntimeTestInfo( AbstractTestTools.getTestRootDir("com.android.jack.cast.implicit001"), "com.android.jack.cast.implicit001.dx.Tests"); @@ -63,6 +67,7 @@ public class CastTests extends RuntimeTest { public static void setUpClass() { CastTests.class.getClassLoader().setDefaultAssertionStatus(true); } + @Test @Category(RuntimeRegressionTest.class) public void explicit001() throws Exception { @@ -71,6 +76,12 @@ public class CastTests extends RuntimeTest { @Test @Category(RuntimeRegressionTest.class) + public void explicit002() throws Exception { + new RuntimeTestHelper(EXPLICIT002).compileAndRunTest(); + } + + @Test + @Category(RuntimeRegressionTest.class) public void implicit001() throws Exception { new RuntimeTestHelper(IMPLICIT001).compileAndRunTest(); } @@ -129,6 +140,7 @@ public class CastTests extends RuntimeTest { @Override protected void fillRtTestInfos() { rtTestInfos.add(EXPLICIT001); + rtTestInfos.add(EXPLICIT002); rtTestInfos.add(IMPLICIT001); rtTestInfos.add(IMPLICIT002); rtTestInfos.add(IMPLICIT003); diff --git a/jack-tests/tests/com/android/jack/cast/explicit002/dx/Tests.java b/jack-tests/tests/com/android/jack/cast/explicit002/dx/Tests.java new file mode 100644 index 0000000..4ce0161 --- /dev/null +++ b/jack-tests/tests/com/android/jack/cast/explicit002/dx/Tests.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 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 com.android.jack.cast.explicit002.dx; + +import com.android.jack.cast.explicit002.jack.Explicit002; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests about casting of null. + */ +public class Tests { + + @Test + public void test1() { + try { + Explicit002.castWithNull(); + Assert.fail(); + } catch (NullPointerException e) { + } + } +} diff --git a/jack-tests/tests/com/android/jack/cast/explicit002/jack/Explicit002.java b/jack-tests/tests/com/android/jack/cast/explicit002/jack/Explicit002.java new file mode 100644 index 0000000..b4ea00d --- /dev/null +++ b/jack-tests/tests/com/android/jack/cast/explicit002/jack/Explicit002.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 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 com.android.jack.cast.explicit002.jack; + +public class Explicit002 { + + public static void castWithNull() { + useInt(((int[]) null)[0]); + } + + public static void useInt(int i ) { + } +} -- cgit v1.1