Bug 46122

Summary: Problem doing PPT2PNG
Product: POI Reporter: Enrique Peña <greenpe>
Component: HSLFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.2-dev   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: The .ppt file that causes all this mess

Description Enrique Peña 2008-10-29 11:43:27 UTC
Created attachment 22790 [details]
The .ppt file that causes all this mess

Hello I'm currently using Apache POI HSLF to convert in application to convert flowchart Powerpoint files (.ppt) into .png image files. It works ok, normally, without arrows usually, but I found a new crash while converting a .ppt file.
I have no idea why this is happening.

The sentence that throws NullPointerException is:
/* Code Start */
FileInputStream is = new FileInputStream("greenpe.ppt");
SlideShow ppt = new SlideShow (is);
is.close();
Dimension pgsize = ppt.getPageSize();
Slide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) { 
   BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
   Graphics2D graphics = img.createGraphics();
   graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
   graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
   graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
   graphics.setPaint(Color.white);
   graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

   Slide s = slide[i];
   
   try   {	
       s.draw(graphics);
   } catch (NullPointerException e) {
       e.printStackTrace;
   }
/* Code Finish */


This is the stack trace:
StackTrace: java.lang.NullPointerException
	at org.apache.poi.hslf.model.Picture.getEscherBSERecord(Picture.java:200)
	at org.apache.poi.hslf.model.Picture.getPictureData(Picture.java:180)
	at org.apache.poi.hslf.model.Picture.draw(Picture.java:265)
	at org.apache.poi.hslf.model.ShapeGroup.draw(ShapeGroup.java:280)
	at org.apache.poi.hslf.model.Slide.draw(Slide.java:431)
	at ... (...MyComponent.java:381)


Any idea? Thanks
Comment 1 Yegor Kozlov 2008-11-03 09:57:47 UTC
Fixed in r710114

One of the shapes has type=Picture but the reference to picture data is invalid. I fixed Picture.draw to skip rendering of such "invalid" pictures. 

Yegor