Object.wait( long timeout ) does not wait for notification if the value of timeout =
Long.MAX_VALUE - 1. It does wait for Long.MAX_VALUE.
Steps to reproduce
Compile and run the attached code
import java.io.PrintStream;
public class WaitTests {
PrintStream out = System.out;
public static void main(String[] argv) {
Object0035();
Object0036();
}
//Test Object0035: Test Object.wait( Long.MAX_VALUE - 1 )
void Object0035() {
int st = 0;
WaitObject o = new WaitObject( out, 5000 );
o.start();
try {
st = o.getState( Long.MAX_VALUE - 1L );
}
catch( InterruptedException e ) {
out.println( "Another thread has interrupted" );
our.println( "Object0035: Another Thread interrupted" );
return;
}
if( st == 12 )
out.println( "Object0035: OKAY" );
else
out.println( "Object0035: did not wait for notify" );
}
//Test Object0036: Test Object.wait( Long.MAX_VALUE )
void Object0036() {
int st = 0;
WaitObject o = new WaitObject( out, 5000 );
o.start();
try {
st = o.getState( Long.MAX_VALUE );
}
catch( InterruptedException e ) {
out.println( "Another thread has interrupted" );
out.println( "Object0036: Another Thread interrupted" );
return;
}
if( st == 12 )
out.println( "Object0036: OKAY" );
else
out.println( "Object0036: did not wait for notify" );
}
}
class WaitObject extends Thread {
private int state = 0;
private long sleepTime = 0;
private PrintStream out;
public WaitObject( PrintStream out, long sleepTime ) {
this.sleepTime = sleepTime;
this.out = out;
}
public synchronized void setState( int i ) {
out.println( "Setting State" );
state = i;
notify();
}
public synchronized int getState( ) throws InterruptedException {
out.println( "Waiting for state..." );
wait();
out.println( "Getting State" );
return state;
}
public synchronized int getState( long waitTime )
throws InterruptedException
{
out.println( "Waiting for state ..." );
wait( waitTime );
out.println( "Getting State" );
return state;
}
public synchronized int getState( long waitTime, int nanos )
throws InterruptedException
{
out.println( "Waiting for state..." );
wait( waitTime, nanos );
out.println( "Getting State" );
return state;
}
public synchronized void run() {
try {
sleep( sleepTime );
}
catch( InterruptedException e ) {}
setState( 12 );
}
}
The description field as copied from bug report 1261827 follows:
This bug report includes a description and test of the bug in 1254002, but includes another case. On the outside chance that they're actually different problems, here's another bug.
From: Ludovic Poitou - SunSoft ICNC <Ludovic.Poitou@France>
This does not look like form output to me.
This is a BUG, on JDK 1.0.2.
wait (long timeout) from class Object exits immediately when the timeout value
is bigger than Integer.MAX_VALUE (excepted for Long.MAX_VALUE).
The bug has been discovered on an SS5 running Solaris 2.5.1, while testing a
Java networking application.
Following is an example that show the bug.
Regards,
Ludovic Poitou
import java.lang.*;
class BugWait extends Thread
{
static public void main(String args[])
{
BugWait bug = new BugWait();
bug.start();
}
public synchronized void run()
{
long wait_param;
/* Wait doesn't wait !! */
wait_param = Long.MAX_VALUE - 1L;
System.out.println("WAIT(" + wait_param + ") = Long.MAX_VALUE - 1");
try {
long Now = System.currentTimeMillis();
wait(wait_param);
System.out.println("Waited for " + (long)(System.currentTimeMillis() -
Now));
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
}
System.out.println("--- Next test ---");
/* Wait doesn't wait !! */
wait_param = ((long) Integer.MAX_VALUE) + 1L;
System.out.println("WAIT(" + wait_param + ") = Integer.MAX_VALUE + 1");
try {
long Now = System.currentTimeMillis();
wait(wait_param);
System.out.println("Waited for " + (long)(System.currentTimeMillis() -
Now));
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
}
System.out.println("--- Next test ---");
System.out.println("Works with the following values...\\nYou should interrupt it with ^C (it'll wait for a long time)");
wait_param = Long.MAX_VALUE;
System.out.println("WAIT(" + wait_param + ") = Long.MAX_VALUE");
// wait_param = Integer.MAX_VALUE;
// System.out.println("WAIT(" + wait_param + ") = Integer.MAX_VALUE");
// wait_param = ((long) Integer.MAX_VALUE) - 1L;
// System.out.println("WAIT(" + wait_param + ") = Integer.MAX_VALUE - 1");
try {
long Now = System.currentTimeMillis();
wait(wait_param);
System.out.println("Waited for " + (long)(System.currentTimeMillis() -
Now));
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
}
System.out.println("--- End of test ---");
}
}
Long.MAX_VALUE - 1. It does wait for Long.MAX_VALUE.
Steps to reproduce
Compile and run the attached code
import java.io.PrintStream;
public class WaitTests {
PrintStream out = System.out;
public static void main(String[] argv) {
Object0035();
Object0036();
}
//Test Object0035: Test Object.wait( Long.MAX_VALUE - 1 )
void Object0035() {
int st = 0;
WaitObject o = new WaitObject( out, 5000 );
o.start();
try {
st = o.getState( Long.MAX_VALUE - 1L );
}
catch( InterruptedException e ) {
out.println( "Another thread has interrupted" );
our.println( "Object0035: Another Thread interrupted" );
return;
}
if( st == 12 )
out.println( "Object0035: OKAY" );
else
out.println( "Object0035: did not wait for notify" );
}
//Test Object0036: Test Object.wait( Long.MAX_VALUE )
void Object0036() {
int st = 0;
WaitObject o = new WaitObject( out, 5000 );
o.start();
try {
st = o.getState( Long.MAX_VALUE );
}
catch( InterruptedException e ) {
out.println( "Another thread has interrupted" );
out.println( "Object0036: Another Thread interrupted" );
return;
}
if( st == 12 )
out.println( "Object0036: OKAY" );
else
out.println( "Object0036: did not wait for notify" );
}
}
class WaitObject extends Thread {
private int state = 0;
private long sleepTime = 0;
private PrintStream out;
public WaitObject( PrintStream out, long sleepTime ) {
this.sleepTime = sleepTime;
this.out = out;
}
public synchronized void setState( int i ) {
out.println( "Setting State" );
state = i;
notify();
}
public synchronized int getState( ) throws InterruptedException {
out.println( "Waiting for state..." );
wait();
out.println( "Getting State" );
return state;
}
public synchronized int getState( long waitTime )
throws InterruptedException
{
out.println( "Waiting for state ..." );
wait( waitTime );
out.println( "Getting State" );
return state;
}
public synchronized int getState( long waitTime, int nanos )
throws InterruptedException
{
out.println( "Waiting for state..." );
wait( waitTime, nanos );
out.println( "Getting State" );
return state;
}
public synchronized void run() {
try {
sleep( sleepTime );
}
catch( InterruptedException e ) {}
setState( 12 );
}
}
The description field as copied from bug report 1261827 follows:
This bug report includes a description and test of the bug in 1254002, but includes another case. On the outside chance that they're actually different problems, here's another bug.
From: Ludovic Poitou - SunSoft ICNC <Ludovic.Poitou@France>
This does not look like form output to me.
This is a BUG, on JDK 1.0.2.
wait (long timeout) from class Object exits immediately when the timeout value
is bigger than Integer.MAX_VALUE (excepted for Long.MAX_VALUE).
The bug has been discovered on an SS5 running Solaris 2.5.1, while testing a
Java networking application.
Following is an example that show the bug.
Regards,
Ludovic Poitou
import java.lang.*;
class BugWait extends Thread
{
static public void main(String args[])
{
BugWait bug = new BugWait();
bug.start();
}
public synchronized void run()
{
long wait_param;
/* Wait doesn't wait !! */
wait_param = Long.MAX_VALUE - 1L;
System.out.println("WAIT(" + wait_param + ") = Long.MAX_VALUE - 1");
try {
long Now = System.currentTimeMillis();
wait(wait_param);
System.out.println("Waited for " + (long)(System.currentTimeMillis() -
Now));
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
}
System.out.println("--- Next test ---");
/* Wait doesn't wait !! */
wait_param = ((long) Integer.MAX_VALUE) + 1L;
System.out.println("WAIT(" + wait_param + ") = Integer.MAX_VALUE + 1");
try {
long Now = System.currentTimeMillis();
wait(wait_param);
System.out.println("Waited for " + (long)(System.currentTimeMillis() -
Now));
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
}
System.out.println("--- Next test ---");
System.out.println("Works with the following values...\\nYou should interrupt it with ^C (it'll wait for a long time)");
wait_param = Long.MAX_VALUE;
System.out.println("WAIT(" + wait_param + ") = Long.MAX_VALUE");
// wait_param = Integer.MAX_VALUE;
// System.out.println("WAIT(" + wait_param + ") = Integer.MAX_VALUE");
// wait_param = ((long) Integer.MAX_VALUE) - 1L;
// System.out.println("WAIT(" + wait_param + ") = Integer.MAX_VALUE - 1");
try {
long Now = System.currentTimeMillis();
wait(wait_param);
System.out.println("Waited for " + (long)(System.currentTimeMillis() -
Now));
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
}
System.out.println("--- End of test ---");
}
}
- duplicates
-
JDK-1261827 fp.bugs 5111 Object.wait() doesn't for integer.MAXVALUE+1 either
-
- Closed
-