Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8055839

[macosx] OutOfMemoryError when calling TableColumn.setPreferredWidth()

    XMLWordPrintable

Details

    Backports

      Description

        FULL PRODUCT VERSION :
        java version "1.7.0_05"
        Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
        Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Mac OS X 10.7.4

        A DESCRIPTION OF THE PROBLEM :
        The test class demonstrates an OutOfMemoryError that occurs on Mac OS X 10.7.4 running Java 1.7.0_05 (using default JVM parms) and the Mac OS X look and feel. The problem happen when having a very large string in single column JTable. It occurs at a certain level while increasing the value of TableColumn.setPreferredWidth(). Just before the OutOfMemoryError happen some garbage graphics is painted in the table header.

        For me the garbage in the table header is painted with some random garbage graphics when setting preferred width to a value around 16000 (scroll horizontally and the garbage will appear). The OutOfMemoryError occur at a value of approx +20000 and when clicking in the table. This is the full error:

        Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: can't create offscreen surface
        at sun.java2d.opengl.OGLSurfaceData.initSurfaceNow(OGLSurfaceData.java:298)
        at sun.java2d.opengl.OGLSurfaceData.access$000(OGLSurfaceData.java:98)
        at sun.java2d.opengl.OGLSurfaceData$1.run(OGLSurfaceData.java:324)
        at sun.java2d.opengl.OGLRenderQueue$QueueFlusher.run(OGLRenderQueue.java:234)

        I've tried the JVM properties to enable/disable OpenGL, Quartz and other properties but the error is still produced.

        Running the same test program with Java 1.6.0_33 works fine with a preferred width set to several millions. Note the problem occur only with the Mac OS X L&F. I've tried Metal and Alloy and these work fine.


        REGRESSION. Last worked in version 6u31

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1) Start the program
        2) Increase the value for preferred width to 10000. Click in the cell, all is fine.
        3) Increase the value to 16000 and press enter and scroll to the right. There will be garbage graphics in the table header
        4) Increase the value to 20000 and click in the cell. An OutOfMemoryException is now displayed in the console

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Should work increasing the preferredWidth without any exception being reported
        ACTUAL -
        See Steps to Reproduce above.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: can't create offscreen surface
        at sun.java2d.opengl.OGLSurfaceData.initSurfaceNow(OGLSurfaceData.java:298)
        at sun.java2d.opengl.OGLSurfaceData.access$000(OGLSurfaceData.java:98)
        at sun.java2d.opengl.OGLSurfaceData$1.run(OGLSurfaceData.java:324)
        at sun.java2d.opengl.OGLRenderQueue$QueueFlusher.run(OGLRenderQueue.java:234)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.BorderLayout;
        import java.awt.FlowLayout;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;

        import javax.swing.*;
        import javax.swing.table.AbstractTableModel;

        /**
         * This test class demonstrates an OutOfMemoryError that occurs on Mac OS X 10.7.4
         * running Java 1.7.0_05 (using default JVM parms) and the Mac OS X look and feel.
         * The problem happen when having a very large string in single column JTable.
         * It occurs at a certain level when increasing the value of
         * TableColumn.setPreferredWidth(). Just before the OutOfMemoryError happen
         * some garbage graphics is painted in the table header.
         *
         * For me the garbage in the table header is rendered when setting preferred width
         * to a value around 16000 (scroll horizontally and the garbage will appear).
         * The OutOfMemoryError occur at a value of approx +20000 and when clicking in
         * the table. This is the full error:
         *
         * Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: can't create offscreen surface
         * at sun.java2d.opengl.OGLSurfaceData.initSurfaceNow(OGLSurfaceData.java:298)
         * at sun.java2d.opengl.OGLSurfaceData.access$000(OGLSurfaceData.java:98)
         * at sun.java2d.opengl.OGLSurfaceData$1.run(OGLSurfaceData.java:324)
         * at sun.java2d.opengl.OGLRenderQueue$QueueFlusher.run(OGLRenderQueue.java:234)
         *
         * Running the same test program with Java 1.6.0_33 works fine with a preferred
         * width set to several millions.
         *
         * Note the problem occur only with the Mac OS X L&F. I've tried Metal and Alloy
         * and these work fine.
         */
        public class BigStringErrorOnOSX extends JFrame {

           public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                 @Override
                 public void run() {
                    BigStringErrorOnOSX t = new BigStringErrorOnOSX();
                    t.setSize(1000, 200);
                    t.setVisible(true);
                 }
              });
           }

           public BigStringErrorOnOSX() {
              final JTable table = new JTable(new DummyModel());
              table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

              final JTextField widthField = new JTextField(10);
              widthField.addActionListener(new ActionListener() {
                 @Override
                 public void actionPerformed(ActionEvent e) {
                    table.getColumnModel().getColumn(0).setPreferredWidth(Integer.parseInt(widthField.getText()));
                 }
              });
              JPanel topPanel = new JPanel(new FlowLayout());
              topPanel.add(new JLabel("setPreferredWidth for column 0:"));
              topPanel.add(widthField);

              add(topPanel, BorderLayout.NORTH);
              add(new JScrollPane(table), BorderLayout.CENTER);
           }

           class DummyModel extends AbstractTableModel {
              private String bigString;

              DummyModel() {
                 StringBuilder b = new StringBuilder();
                 int n = 0;
                 for (int i = 0; i < 100000; i++) {
                    b.append(n++);
                    if (n > 9) {
                       n = 0;
                    }
                 }
                 bigString = b.toString();
              }

              @Override
              public int getRowCount() {
                 return 1;
              }

              @Override
              public int getColumnCount() {
                 return 1;
              }

              @Override
              public Object getValueAt(int rowIndex, int columnIndex) {
                 return bigString;
              }
           }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Don't use the Mac OS X look and feel

        Attachments

          Issue Links

            Activity

              People

                alexsch Alexandr Scherbatiy
                alitvinov Anton Litvinov (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported: