harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Elena Semukhina (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-66) java.lang.SecurityManager.checkAccess(Thread t) throws NullPointerException for the dead thread.
Date Wed, 01 Feb 2006 10:42:03 GMT
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


Mime
View raw message