You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by "Elena Semukhina (JIRA)" <ji...@apache.org> on 2006/02/01 11:42:03 UTC

[jira] Created: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.

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
    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


[jira] Commented: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.

Posted by "Elena Semukhina (JIRA)" <ji...@apache.org>.
    [ 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


[jira] Resolved: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-66?page=all ]
     
Tim Ellison resolved HARMONY-66:
--------------------------------

    Resolution: Fixed

Elena,

Fixed in LUNI module java.lang.SecurityManager at repo revision 374062.

Please check that this fully resolves your problem.


> 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


[jira] Reopened: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-66?page=all ]
     
Tim Ellison reopened HARMONY-66:
--------------------------------


Fair comments -- let me look at this again.

> 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


[jira] Resolved: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-66?page=all ]
     
Tim Ellison resolved HARMONY-66:
--------------------------------

    Resolution: Fixed

Elena,

Thanks to you checks I have revised the fix.
Now fixed in LUNI java.lang.SecurityManager at repo revision 374380.

Please will you review and check again.


> 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


[jira] Assigned: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-66?page=all ]

Tim Ellison reassigned HARMONY-66:
----------------------------------

    Assign To: Tim Ellison

> 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


[jira] Closed: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-66?page=all ]
     
Tim Ellison closed HARMONY-66:
------------------------------


Verified by Elena.


> 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


[jira] Commented: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.

Posted by "Elena Semukhina (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-66?page=comments#action_12365048 ] 

Elena Semukhina commented on HARMONY-66:
----------------------------------------

Tim,

this time the fix looks fine and the test passes.


> 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


[jira] Commented: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.

Posted by "Stepan Mishura (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-66?page=comments#action_12364938 ] 

Stepan Mishura commented on HARMONY-66:
---------------------------------------

I've looked into added regression test case and I have the following comment:
The current test case will pass if the method checkAccess() returns silently or AccessControlException is thrown. I think the test case should be stricter and pass only in one case. Otherwise the test case may mask a bug in Harmony implementation.

In our case a security manager is not installed by default and the test case doesn't install it too. As far as I understand the spec. the method checkPermission should not be invoked so no AccessControlException is thrown. However Harmony implementation throws exception.


> 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