Name: dk106046 Date: 07/13/2004
Compile and run the following program.
The setPriority method call will raise a NullPointerException.
public class Npe extends java.lang.Thread {
public void run(){
try{
Thread.sleep(500);
}catch(java.lang.InterruptedException e){}
}
public static void main(String[] args){
Npe npe = new Npe();
npe.start();
try{
npe.join();
}catch(java.lang.InterruptedException e){}
npe.setPriority(java.lang.Thread.MIN_PRIORITY);
}
}
The error message:
Exception in thread "main" java.lang.NullPointerException
at java.lang.Thread.setPriority(Thread.java:875)
at Npe.main(Npe.java:18)
obviously the line number in Thread.java will vary by build
======================================================================
Compile and run the following program.
The setPriority method call will raise a NullPointerException.
public class Npe extends java.lang.Thread {
public void run(){
try{
Thread.sleep(500);
}catch(java.lang.InterruptedException e){}
}
public static void main(String[] args){
Npe npe = new Npe();
npe.start();
try{
npe.join();
}catch(java.lang.InterruptedException e){}
npe.setPriority(java.lang.Thread.MIN_PRIORITY);
}
}
The error message:
Exception in thread "main" java.lang.NullPointerException
at java.lang.Thread.setPriority(Thread.java:875)
at Npe.main(Npe.java:18)
obviously the line number in Thread.java will vary by build
======================================================================
- duplicates
-
JDK-4515956 (thread) Thread.setPriority on dead thread throws NullPointerException
-
- Closed
-
-
JDK-5037861 (thread) Thread.setPriority() throws NullPointerException if thread has exited
-
- Closed
-