JDK-8055839 : [macosx] OutOfMemoryError when calling TableColumn.setPreferredWidth()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,7u5,8,9
  • Priority: P2
  • Status: Resolved
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2012-07-05
  • Updated: 2015-02-10
  • Resolved: 2015-02-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Resolved 9Resolved
Related Reports
Duplicate :  
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

Comments
This is the duplicate of the issue JDK-8040617 [macosx] Large JTable cell results in a OutOfMemoryException
10-02-2015

300 reports from NetBeans users so far. Being reported every day. Raising priority to P2. NetBeans bug: https://netbeans.org/bugzilla/show_bug.cgi?id=241562 Exception reports: http://statistics.netbeans.org/exceptions/detail.do?id=207403
23-12-2014

not a regression for 8 and 9
12-12-2014

The bug was reproduced by means of the test case specified in the description of the bug with JDK 9 b26, JDK 8u20 b26, JDK 7u67 b01 on OS X 10.9.1. Was able to see that the bug is not reproducible with: - JDK 1.6.0_65-b14-462-11M4609 from Apple - JDKs specified in the previous sentence but with Metal L&F enabled.
22-08-2014