[
http://issues.apache.org/jira/browse/HARMONY-66?page=comments#action_12364939 ]
Elena Semukhina commented on HARMONY-66:
----------------------------------------
Tim,
unfortunately the fix is not correct. Now the test fails on checking permission
as follows:
Exception in thread "main" java.security.AccessControlException: Access denied
(java.lang.RuntimePermission modifyThread)
at java.security.AccessController.checkPermission(AccessController.java:
90)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:704)
at java.lang.SecurityManager.checkAccess(SecurityManager.java:94)
at ThreadCheckAccess.test(ThreadCheckAccess.java:24)
at ThreadCheckAccess.main(ThreadCheckAccess.java:33)
The point is that SecurityManager.checkAccess(Thread) should call
checkPermission only for system threads, otherwise it should return silently.
> java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException
> for the dead thread.
> ------------------------------------------------------------------------------------------------
>
> Key: HARMONY-66
> URL: http://issues.apache.org/jira/browse/HARMONY-66
> Project: Harmony
> Type: Bug
> Components: Classlib
> Reporter: Elena Semukhina
> Assignee: Tim Ellison
> Priority: Minor
>
> java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException
> for the dead thread.
> According to specification, the Thread.getThreadGroup() method returns null
> if this thread has died.
> SecurityManager.checkAccess(Thread t) should take that into account.
> Code for reproducing:
> public class ThreadCheckAccess {
> class ThreadRunning extends Thread {
> volatile boolean stopWork = false;
> int i = 0;
> public void run () {
> while (!stopWork) {
> }
> }
> }
> public void test() {
> SecurityManager sm = new SecurityManager();
> System.setSecurityManager(sm);
> ThreadRunning t = new ThreadRunning();
> t.start();
> t.stopWork = true;
> try {
> t.join();
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> try {
> sm.checkAccess(t);
> System.out.println("PASSED");
> } catch (NullPointerException e) {
> e.printStackTrace();
> System.out.println("FAILED");
> }
> }
> public static void main(String args[]) {
> new ThreadCheckAccess().test();
> }
> }
> Steps to Reproduce:
> 1. Build Harmony (check-out on 2006-01-31) j2se subset as described in
> README.txt.
> 2. Compile ThreadCheckAccess.java using BEA 1.4 javac
> > javac -d . ThreadCheckAccess.java
> 2. Run java using compatible VM (J9)
> > java -showversion ThreadCheckAccess
>
> Output:
> java version 1.4.2 (subset)
> (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as
> applicable.
> java.lang.NullPointerException
> at java.lang.SecurityManager.checkAccess(SecurityManager.java:92)
> at java.lang.Thread.checkAccess(Thread.java:423)
> at ThreadCheckAccess.test(ThreadCheckAccess.java:23)
> at ThreadCheckAccess.main(ThreadCheckAccess.java:32)
> FAILED
> Output on BEA 1.4.2:
> PASSED
> Suggested junit test case:
> package org.apache.harmony.tests.java.lang;
> import junit.framework.TestCase;
> public class SecurityManagerTest extends TestCase {
> class ThreadRunning extends Thread {
> volatile boolean stopWork = false;
> int i = 0;
> public void run () {
> while (!stopWork) {
> }
> }
> }
> public void test_checkAccessLjava_lang_Thread() {
> SecurityManager sm = new SecurityManager();
> System.setSecurityManager(sm);
> ThreadRunning t = new ThreadRunning();
> t.start();
> t.stopWork = true;
> try {
> t.join();
> } catch (InterruptedException e) {
> fail("Assert 0: unexpected " + e);
> }
> try {
> sm.checkAccess(t);
> } catch (NullPointerException e) {
> fail("Assert 1: NullPointerException has been thrown");
> }
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira