0

If my java code makes a call to any javax.ImageIO method, it throws a silent error. e.g.

File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try
{
   BufferedImage fullImg = ImageIO.read(screenshot);
}
catch(Exception e)
{
   e.printStackTrace();
}

no error message is produced, but the code halts at that point. I tried calling ImageIO.getReaderFormatNames() just to see, but it also throws a silent error. This problem occurs in Ubuntu with oracle jre (java version "1.8.0_60") installed. Please note that the same code works perfectly fine in Windows (10). I have tried with FileInputStream as well

FileInputStream fis = new FileInputStream(screenshot);
BufferedImage fullImg = ImageIO.read(fis);
chenzen
  • 63
  • 1
  • 1
  • 7
  • Can you step through in the debugger? – Neil Coffey Oct 16 '15 at 20:53
  • Since its stopping, it's probably not failing, it's just not competing. How does getScreenshotAs work? – MadProgrammer Oct 16 '15 at 20:58
  • @MadProgrammer i meant anything after the line conatining ImageIO.read() inside try{} block doesn't execute, as to be expected when that line is supposed to be throwing an error. – chenzen Oct 16 '15 at 21:05
  • 1
    @chenzen So nothing within the `try {...}` executes after the `ImageIO.read`, BUT you're not getting an `Exception`? Try catching `Throwable` and see if that shows anything – MadProgrammer Oct 16 '15 at 21:13
  • @MadProgrammer thanks. after catching throwable, i found out that my system is missing libxtst6. installed it and it is working smoothly :) – chenzen Oct 16 '15 at 21:45
  • 1
    Feel free to add that as answer, highlighting the OS and Java versions, it's possible someone might face a similar problem ;) – MadProgrammer Oct 16 '15 at 21:50

1 Answers1

2

I solved the problem after @MadProgrammer suggested me to catch Throwable instead of Exception to debug. I found out that my Ubuntu 15.04 machine doesn't have libxtst6 installed, leading to the following error

java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-8-oracle/jre/lib/amd64/libawt_xawt.so: libXtst.so.6: cannot open shared object file: No such file or directory

which ended up causing the following NoClassDefFoundError

java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIO

My java version is 1.8.0_60 Hope it helps others facing similar issues.

chenzen
  • 63
  • 1
  • 1
  • 7
  • I had the same problem on a debian 9 system. Worked now for 7h on this, completely no stack trace or anything, additionally logging issues with my logback.xml. Terrible. Thanks for pointing me finally in the right direction! – mr.simonski Jul 31 '17 at 22:19