-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.4.2
-
x86
-
linux
FULL PRODUCT VERSION :
java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Red Hat 9.
Linux 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Our application uses the AwtRobot to take screenshots. It also uses the JavaPOS device driver API to communicate with USB connected hardware (barcode scanners).
The native part of the driver needs to open a file handle on a file in the /dev filesystem to communicate with the device. It has to open this handle in exclusive mode.
When the awt_robot process is started it inherits all the parent's file handles. When the main application tries to reinitialise the communication with the device, the native driver closes its file handle. awt_robot still has the handle open at that time.
When the main application tries to re-open the device, the native driver attempts to open the device exclusively again, failing, because the awt_robot still has a handle.
This breaks our application.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
You need a device node that is opened in exclusive mode by its driver module.
Then run the attached test program providing the file name in /dev as a parameter.
See error message.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
awt_robot should not inherit all parent's resources. It should only communicate with its parent via a well defined interface and not use any other resources on the file system.
ACTUAL -
awt_robot inherits all handles.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
# java RobotTest /dev/wn_javapos_genusb8
Open /dev/wn_javapos_genusb8...done
Creating Robot...done
Taking screenshot...done
Closing /dev/wn_javapos_genusb8...done
Sleeping 5s, Kill awt_robot now to proceed normally
Reopen /dev/wn_javapos_genusb8...Exception in thread "main" java.io.FileNotFoundException: /dev/wn_javapos_genusb8 (File exists)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:204)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:94)
at RobotTest.main(RobotTest.java:38)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.io.*;
public class RobotTest {
private static String deviceFile;
private static void outl(String aString) {
System.out.println(aString);
}
private static void out(String aString) {
System.out.print(aString);
}
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Specify device node!");
System.exit(1);
}
deviceFile=args[0];
out("Open " + deviceFile + "...");
RandomAccessFile tRAF = new RandomAccessFile(deviceFile, "rw");
outl("done");
out("Creating Robot...");
Robot tRobot = new Robot();
outl("done");
Toolkit tToolkit = Toolkit.getDefaultToolkit();
Dimension tDimension = tToolkit.getScreenSize();
out("Taking screenshot...");
Image tBackground = tRobot.createScreenCapture(new Rectangle(0, 0, (int)tDimension.getWidth(), (int)tDimension.getHeight()));
outl("done");
out("Closing " + deviceFile + "...");
tRAF.close();
outl("done");
outl("Sleeping 5s, Kill awt_robot now to proceed normally");
Thread.sleep(5000L);
out("Reopen " + deviceFile + "...");
tRAF = new RandomAccessFile(deviceFile, "rw");
outl("done.");
out("Closing " + deviceFile + "...");
tRAF.close();
outl("done.");
outl("Exiting");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use Awt-Robot, if possible.
java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Red Hat 9.
Linux 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Our application uses the AwtRobot to take screenshots. It also uses the JavaPOS device driver API to communicate with USB connected hardware (barcode scanners).
The native part of the driver needs to open a file handle on a file in the /dev filesystem to communicate with the device. It has to open this handle in exclusive mode.
When the awt_robot process is started it inherits all the parent's file handles. When the main application tries to reinitialise the communication with the device, the native driver closes its file handle. awt_robot still has the handle open at that time.
When the main application tries to re-open the device, the native driver attempts to open the device exclusively again, failing, because the awt_robot still has a handle.
This breaks our application.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
You need a device node that is opened in exclusive mode by its driver module.
Then run the attached test program providing the file name in /dev as a parameter.
See error message.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
awt_robot should not inherit all parent's resources. It should only communicate with its parent via a well defined interface and not use any other resources on the file system.
ACTUAL -
awt_robot inherits all handles.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
# java RobotTest /dev/wn_javapos_genusb8
Open /dev/wn_javapos_genusb8...done
Creating Robot...done
Taking screenshot...done
Closing /dev/wn_javapos_genusb8...done
Sleeping 5s, Kill awt_robot now to proceed normally
Reopen /dev/wn_javapos_genusb8...Exception in thread "main" java.io.FileNotFoundException: /dev/wn_javapos_genusb8 (File exists)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:204)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:94)
at RobotTest.main(RobotTest.java:38)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.io.*;
public class RobotTest {
private static String deviceFile;
private static void outl(String aString) {
System.out.println(aString);
}
private static void out(String aString) {
System.out.print(aString);
}
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Specify device node!");
System.exit(1);
}
deviceFile=args[0];
out("Open " + deviceFile + "...");
RandomAccessFile tRAF = new RandomAccessFile(deviceFile, "rw");
outl("done");
out("Creating Robot...");
Robot tRobot = new Robot();
outl("done");
Toolkit tToolkit = Toolkit.getDefaultToolkit();
Dimension tDimension = tToolkit.getScreenSize();
out("Taking screenshot...");
Image tBackground = tRobot.createScreenCapture(new Rectangle(0, 0, (int)tDimension.getWidth(), (int)tDimension.getHeight()));
outl("done");
out("Closing " + deviceFile + "...");
tRAF.close();
outl("done");
outl("Sleeping 5s, Kill awt_robot now to proceed normally");
Thread.sleep(5000L);
out("Reopen " + deviceFile + "...");
tRAF = new RandomAccessFile(deviceFile, "rw");
outl("done.");
out("Closing " + deviceFile + "...");
tRAF.close();
outl("done.");
outl("Exiting");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use Awt-Robot, if possible.
- relates to
-
JDK-6287244 Linux/Solaris robot should be rewritten
- Resolved