diff options
Diffstat (limited to 'test/024-illegal-access')
-rw-r--r-- | test/024-illegal-access/expected.txt | 2 | ||||
-rw-r--r-- | test/024-illegal-access/info.txt | 3 | ||||
-rw-r--r-- | test/024-illegal-access/src/CheckInstanceof.java | 27 | ||||
-rw-r--r-- | test/024-illegal-access/src/Main.java | 41 | ||||
-rw-r--r-- | test/024-illegal-access/src/PublicAccess.java | 11 | ||||
-rw-r--r-- | test/024-illegal-access/src/SemiPrivate.java | 8 | ||||
-rw-r--r-- | test/024-illegal-access/src/otherpkg/Package.java | 23 | ||||
-rw-r--r-- | test/024-illegal-access/src2/SemiPrivate.java | 8 | ||||
-rw-r--r-- | test/024-illegal-access/src2/otherpkg/Package.java | 23 |
9 files changed, 146 insertions, 0 deletions
diff --git a/test/024-illegal-access/expected.txt b/test/024-illegal-access/expected.txt new file mode 100644 index 0000000000..5f951f4939 --- /dev/null +++ b/test/024-illegal-access/expected.txt @@ -0,0 +1,2 @@ +Got expected failure 1 +Got expected failure 2 diff --git a/test/024-illegal-access/info.txt b/test/024-illegal-access/info.txt new file mode 100644 index 0000000000..16a284dace --- /dev/null +++ b/test/024-illegal-access/info.txt @@ -0,0 +1,3 @@ +Test that an attempt to access a private field results in a verification +error. Also try to access a non-public class in a different package with +"instanceof". diff --git a/test/024-illegal-access/src/CheckInstanceof.java b/test/024-illegal-access/src/CheckInstanceof.java new file mode 100644 index 0000000000..de48cd2d28 --- /dev/null +++ b/test/024-illegal-access/src/CheckInstanceof.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2009 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. + */ + +/** + * Make sure we're performing access checks on classes used in "instanceof". + */ +public class CheckInstanceof { + public static void main(Object obj) { + if (obj instanceof otherpkg.Package) + System.out.println("yes!"); + else + System.out.println("no!"); + } +} diff --git a/test/024-illegal-access/src/Main.java b/test/024-illegal-access/src/Main.java new file mode 100644 index 0000000000..bde73e9452 --- /dev/null +++ b/test/024-illegal-access/src/Main.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2009 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 Main { + static public void main(String[] args) { + try { + PublicAccess.main(); + System.err.println("ERROR: call 1 not expected to succeed"); + } catch (VerifyError ve) { + // dalvik + System.out.println("Got expected failure 1"); + } catch (IllegalAccessError iae) { + // reference + System.out.println("Got expected failure 1"); + } + + try { + CheckInstanceof.main(new Object()); + System.err.println("ERROR: call 2 not expected to succeed"); + } catch (VerifyError ve) { + // dalvik + System.out.println("Got expected failure 2"); + } catch (IllegalAccessError iae) { + // reference + System.out.println("Got expected failure 2"); + } + } +} diff --git a/test/024-illegal-access/src/PublicAccess.java b/test/024-illegal-access/src/PublicAccess.java new file mode 100644 index 0000000000..fdc0e9e707 --- /dev/null +++ b/test/024-illegal-access/src/PublicAccess.java @@ -0,0 +1,11 @@ +// Copyright 2006 The Android Open Source Project + +/** + * Some stuff for access checks. + */ +public class PublicAccess { + public static void main() { + String shouldFail = SemiPrivate.mPrivvy; + System.out.println("Got " + shouldFail); + } +} diff --git a/test/024-illegal-access/src/SemiPrivate.java b/test/024-illegal-access/src/SemiPrivate.java new file mode 100644 index 0000000000..17b2ac02f3 --- /dev/null +++ b/test/024-illegal-access/src/SemiPrivate.java @@ -0,0 +1,8 @@ +// Copyright 2006 The Android Open Source Project + +/** + * Version with package scope access. + */ +public class SemiPrivate { + /* not private */ static String mPrivvy = "stuff"; +} diff --git a/test/024-illegal-access/src/otherpkg/Package.java b/test/024-illegal-access/src/otherpkg/Package.java new file mode 100644 index 0000000000..bc295b5a23 --- /dev/null +++ b/test/024-illegal-access/src/otherpkg/Package.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2008 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 otherpkg; + +/* + * Package-scope class (public here). + */ +public class Package { +} diff --git a/test/024-illegal-access/src2/SemiPrivate.java b/test/024-illegal-access/src2/SemiPrivate.java new file mode 100644 index 0000000000..cf6f8e6e1d --- /dev/null +++ b/test/024-illegal-access/src2/SemiPrivate.java @@ -0,0 +1,8 @@ +// Copyright 2006 The Android Open Source Project + +/** + * Version with private access. + */ +public class SemiPrivate { + private static String mPrivvy = "stuff"; +} diff --git a/test/024-illegal-access/src2/otherpkg/Package.java b/test/024-illegal-access/src2/otherpkg/Package.java new file mode 100644 index 0000000000..54d8341878 --- /dev/null +++ b/test/024-illegal-access/src2/otherpkg/Package.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2008 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 otherpkg; + +/* + * Package-scope class. + */ +class Package { +} |