From 207a37dbb8049bdf585d17551c3eb3df685a629f Mon Sep 17 00:00:00 2001 From: Jeff Hao Date: Wed, 29 Oct 2014 17:24:25 -0700 Subject: Check null this pointer for direct methods in FindMethodFast. Also adds regression test 127-secondarydex. Bug: 18150997 (cherry picked from commit d2bee3dffa2f552512f47bca605ed857e3ae30ea) Change-Id: I911dd7c92c51939504cfee5a3d18a835987b8388 --- test/127-secondarydex/build | 31 ++++++++++++++++++++++++++ test/127-secondarydex/expected.txt | 3 +++ test/127-secondarydex/info.txt | 3 +++ test/127-secondarydex/run | 18 +++++++++++++++ test/127-secondarydex/src/Main.java | 43 ++++++++++++++++++++++++++++++++++++ test/127-secondarydex/src/Super.java | 21 ++++++++++++++++++ test/127-secondarydex/src/Test.java | 25 +++++++++++++++++++++ 7 files changed, 144 insertions(+) create mode 100755 test/127-secondarydex/build create mode 100644 test/127-secondarydex/expected.txt create mode 100644 test/127-secondarydex/info.txt create mode 100755 test/127-secondarydex/run create mode 100644 test/127-secondarydex/src/Main.java create mode 100644 test/127-secondarydex/src/Super.java create mode 100644 test/127-secondarydex/src/Test.java (limited to 'test/127-secondarydex') diff --git a/test/127-secondarydex/build b/test/127-secondarydex/build new file mode 100755 index 0000000000..712774f7ef --- /dev/null +++ b/test/127-secondarydex/build @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Copyright (C) 2014 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. + +# Stop if something fails. +set -e + +mkdir classes +${JAVAC} -d classes `find src -name '*.java'` + +mkdir classes-ex +mv classes/Super.class classes-ex + +if [ ${NEED_DEX} = "true" ]; then + ${DX} -JXmx256m --debug --dex --dump-to=classes.lst --output=classes.dex --dump-width=1000 classes + zip $TEST_NAME.jar classes.dex + ${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes.dex --dump-width=1000 classes-ex + zip ${TEST_NAME}-ex.jar classes.dex +fi diff --git a/test/127-secondarydex/expected.txt b/test/127-secondarydex/expected.txt new file mode 100644 index 0000000000..29a1411ad3 --- /dev/null +++ b/test/127-secondarydex/expected.txt @@ -0,0 +1,3 @@ +testSlowPathDirectInvoke +Test +Got null pointer exception diff --git a/test/127-secondarydex/info.txt b/test/127-secondarydex/info.txt new file mode 100644 index 0000000000..0479d1a784 --- /dev/null +++ b/test/127-secondarydex/info.txt @@ -0,0 +1,3 @@ +Test features with a secondary dex file. + +- Regression test to ensure slow path of direct invoke does null check. diff --git a/test/127-secondarydex/run b/test/127-secondarydex/run new file mode 100755 index 0000000000..d8c3c798bf --- /dev/null +++ b/test/127-secondarydex/run @@ -0,0 +1,18 @@ +#!/bin/bash +# +# Copyright (C) 2014 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. + +# Use secondary switch to add secondary dex file to class path. +exec ${RUN} "${@}" --secondary diff --git a/test/127-secondarydex/src/Main.java b/test/127-secondarydex/src/Main.java new file mode 100644 index 0000000000..c921c5b0c8 --- /dev/null +++ b/test/127-secondarydex/src/Main.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 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. + */ + +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +/** + * Secondary dex file test. + */ +public class Main { + public static void main(String[] args) { + testSlowPathDirectInvoke(); + } + + public static void testSlowPathDirectInvoke() { + System.out.println("testSlowPathDirectInvoke"); + try { + Test t1 = new Test(); + Test t2 = new Test(); + Test t3 = null; + t1.test(t2); + t1.test(t3); + } catch (NullPointerException npe) { + System.out.println("Got null pointer exception"); + } catch (Exception e) { + System.out.println("Got unexpected exception " + e); + } + } +} diff --git a/test/127-secondarydex/src/Super.java b/test/127-secondarydex/src/Super.java new file mode 100644 index 0000000000..7608d4a7c8 --- /dev/null +++ b/test/127-secondarydex/src/Super.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2014 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. + */ + +public class Super { + private void print() { + System.out.println("Super"); + } +} diff --git a/test/127-secondarydex/src/Test.java b/test/127-secondarydex/src/Test.java new file mode 100644 index 0000000000..82cb901374 --- /dev/null +++ b/test/127-secondarydex/src/Test.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2014 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. + */ + +public class Test extends Super { + public void test(Test t) { + t.print(); + } + + private void print() { + System.out.println("Test"); + } +} -- cgit v1.2.3