[jbosstools-issues] [JBoss JIRA] (JBIDE-10229) org.jboss.tools.jst.css.dialog.ImageSelectionDialog has GC leaks logik

Alexey Kazakov (Updated) (JIRA) jira-events at lists.jboss.org
Mon Dec 5 14:46:41 EST 2011


     [ https://issues.jboss.org/browse/JBIDE-10229?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexey Kazakov updated JBIDE-10229:
-----------------------------------


Was fixed for 3.3.0.M5
                
> org.jboss.tools.jst.css.dialog.ImageSelectionDialog has GC leaks logik
> ----------------------------------------------------------------------
>
>                 Key: JBIDE-10229
>                 URL: https://issues.jboss.org/browse/JBIDE-10229
>             Project: Tools (JBoss Tools)
>          Issue Type: Sub-task
>          Components: common/jst/core
>    Affects Versions: 3.3.0.M4
>            Reporter: Vitali Yemialyanchyk
>            Assignee: Viacheslav Kabanovich
>             Fix For: 3.3.0.Beta1
>
>
> {code}
>         canvas.addPaintListener(new PaintListener() {
>                 public void paintControl(PaintEvent e) {
>                     GC gc = new GC(canvas);                                           <-------------------------- here you create GC
>                     gc.setForeground(emptyColor);
>                     gc.fillRectangle(1, 1, canvas.getSize().x - 2, canvas.getSize().y - 2);
>                     // resolution.setText("");
>                     resolution.setVisible(false);
>                     if (file != null) {                                                <-------------------------- here you check condition
>                         Cursor parentCursor = getShell().getCursor();
>                         final Cursor waitCursor = new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT);
>                         Point previewPoint = new Point(0, 0);
>                         Point labelPoint = canvas.getSize();
>                         InputStream stream = null;
>                         try {
>                             getShell().setCursor(waitCursor);
>                             stream = new FileInputStream(file.getLocation().toOSString());
>                             ImageData imageData = new ImageData(stream);
>                             stream.close();
>                             if (imageData != null) {
>                                 Image image = new Image(getShell().getDisplay(), imageData);
>                                 // set image in center
>                                 Point imagePoint = new Point(image.getBounds().width,
>                                         image.getBounds().height);
>                                 String imageInfo = imagePoint.x + " x " + imagePoint.y + " px"; //$NON-NLS-1$ //$NON-NLS-2$
>                                 // change resolution if image anymore image label
>                                 if ((imagePoint.x > labelPoint.x) || (imagePoint.y > labelPoint.y)) {
>                                     float ratioImage = (float) imagePoint.x / (float) imagePoint.y;
>                                     if (((imagePoint.y > labelPoint.y) &&
>                                             ((labelPoint.y * ratioImage) > labelPoint.x)) ||
>                                             ((imagePoint.x > labelPoint.x) &&
>                                             ((labelPoint.x / ratioImage) < labelPoint.y))) {
>                                         imageData = imageData.scaledTo(labelPoint.x - 10,
>                                                 (int) (labelPoint.x / ratioImage));
>                                     } else {
>                                         imageData = imageData.scaledTo((int) (labelPoint.y * ratioImage) -
>                                                 10, labelPoint.y);
>                                     }
>                                     image.dispose();
>                                     image = new Image(getShell().getDisplay(), imageData);
>                                     imagePoint.x = image.getBounds().width;
>                                     imagePoint.y = image.getBounds().height;
>                                 }
>                                 previewPoint.x = (labelPoint.x / 2) - (imagePoint.x / 2);
>                                 previewPoint.y = (labelPoint.y / 2) - (imagePoint.y / 2);
>                                 gc.drawImage(image, previewPoint.x, previewPoint.y);
>                                 resolution.setVisible(true);
>                                 resolution.setText(imageInfo);
>                                 image.dispose();
>                                 gc.dispose();                                   <-------------------------- here you dispose
>                             }
>                         } catch (IOException ev) {
>                             //ignore
>                         } catch (SWTException ex) {
>                             //ignore (if select not image file) 
>                         } finally {
>                             getShell().setCursor(parentCursor);
>                             if (stream != null) {
>                                 try {
>                                     stream.close();
>                                 } catch (IOException e1) {
>                                     // ignore
>                                 }
>                             }
>                         }
>                     }
>                 }
>             });
> {code}
> here is absolutely invalid logic, guys :)
> you close the stream in two places - try to find: stream.close();
> I've check a history of changes:
> >>>
> PMD violations fixed.
> InputStreams close() added where it was possible.
> >>>
> 8/29/08 - someone try to close all streams where it possible, after that all of you respect his authority and afraid to fix his error... 
> btw., you are still has a problems with "close of all streams", after 8/29/08 changes...

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jbosstools-issues mailing list