JDK-8201631 : "AWT-EventQueue-0" java.lang.InternalError: Surface not cachable
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8,9,10,11
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2018-04-12
  • Updated: 2021-03-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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Os  : Ubuntu 16.04 LTS  
CPU: x86_32

#uname -a
Linux mypc 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:34:19 UTC 2016 i686 i686 i686 GNU/Linux

JDK version������������
       Openjdk8u40


A DESCRIPTION OF THE PROBLEM :
When you filled the texture with the zoomed picture, an internal exception occurred. 
There is a similar bug in the bug Database, which has been closed because the sample couldn't reproduce. https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8072618

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Generate demo.jar from the project, and place any Image 1.jpg to the same level directory of TextureComponent1.class
2.  java -jar demo.jar

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Exception in thread "AWT-EventQueue-0" java.lang.InternalError: Surface not cachable
	at sun.java2d.xr.XRPaints$XRTexture.getAccSrcSurface(XRPaints.java:211)
	at sun.java2d.xr.XRPaints$XRTexture.isPaintValid(XRPaints.java:224)
	at sun.java2d.xr.XRPaints.isValid(XRPaints.java:75)
	at sun.java2d.xr.XRSurfaceData.getMaskFill(XRSurfaceData.java:205)
	at sun.java2d.SurfaceData.validatePipe(SurfaceData.java:631)
	at sun.java2d.xr.XRSurfaceData.validatePipe(XRSurfaceData.java:123)
	at sun.java2d.SunGraphics2D.validatePipe(SunGraphics2D.java:446)
	at sun.java2d.pipe.ValidatePipe.validate(ValidatePipe.java:55)
	at sun.java2d.pipe.ValidatePipe.fill(ValidatePipe.java:159)
	at sun.java2d.SunGraphics2D.fill(SunGraphics2D.java:2527)
	at demo1.TextureComponent1.paintComponent(TextureComponent1.java:56)
	at javax.swing.JComponent.paint(JComponent.java:1056)
	at javax.swing.JComponent.paintChildren(JComponent.java:889)
	at javax.swing.JComponent.paint(JComponent.java:1065)
	at javax.swing.JComponent.paintChildren(JComponent.java:889)
	at javax.swing.JComponent.paint(JComponent.java:1065)
	at javax.swing.JLayeredPane.paint(JLayeredPane.java:586)
	at javax.swing.JComponent.paintChildren(JComponent.java:889)
	at javax.swing.JComponent.paintToOffscreen(JComponent.java:5226)
	at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:290)
	at javax.swing.RepaintManager.paint(RepaintManager.java:1265)
	at javax.swing.JComponent.paint(JComponent.java:1042)
	at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
	at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:79)
	at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:116)
	at java.awt.Container.paint(Container.java:1973)
	at java.awt.Window.paint(Window.java:3912)
	at javax.swing.RepaintManager$4.run(RepaintManager.java:835)
	at javax.swing.RepaintManager$4.run(RepaintManager.java:807)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:807)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:782)
	at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:731)
	at javax.swing.RepaintManager.access$1300(RepaintManager.java:64)
	at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1720)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749)
	at java.awt.EventQueue.access$500(EventQueue.java:97)
	at java.awt.EventQueue$3.run(EventQueue.java:702)
	at java.awt.EventQueue$3.run(EventQueue.java:696)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:719)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

---------- BEGIN SOURCE ----------
package demo1;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;



public class TextureComponent1 extends JComponent {
	private static final long serialVersionUID = 8449129204443799561L;

	protected Dimension defaultComponentSize = new Dimension(61, 52);

	private BufferedImage bufferedImage;

	/**
	 * ������������������������������������.
	 */
	TextureComponent1() {
	}

	/**
	 * ������������������������������������������������.
	 */
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		try {
			Graphics2D g2d = (Graphics2D) g;
			g2d.clip(new Rectangle(0, 0, 500, 400));
			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			g2d.translate(300, 300);
			g2d.scale(11.1, 31.1);
			Rectangle r = new Rectangle(0, 0, 400, 400);
			int w = 500;
			int h = 500;
			java.awt.RenderingHints oh = g2d.getRenderingHints();
			URL url = TextureComponent1.class.getResource("1.jpg");
			bufferedImage = ImageIO.read(url.openStream());
			bufferedImage = analysisImage(bufferedImage, w, h);
			Paint p = new TexturePaint(bufferedImage, new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()));
			g2d.setPaint(p);
			g2d.fill(r);
			g2d.setRenderingHints(oh);
			g2d.setPaint(Color.black);
			g2d.drawRect(-1, -1, 399, 399);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}

	}
	public static BufferedImage analysisImage(BufferedImage image, int destWidth, int destHeight)
	{

        int width = image.getWidth();
        int height = image.getHeight();            
        if (destWidth == -1 || destHeight == -1)
        {
            return image;
        }
        boolean hasAlpha = image.getColorModel().hasAlpha();
        byte[] byteBuffer = ((DataBufferByte)(image.getRaster().getDataBuffer())).getData();
        
        int[][] pixel = new int[4][];
        for(int i = 0; i < 4; i++)
        {
            pixel[i] = new int[hasAlpha ? 4 : 3];
        }
        
        BufferedImage target = new BufferedImage(destWidth, destHeight, hasAlpha
            ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
        
        float su = (float)width / destWidth;
        float sv = (float)height / destHeight;
        
        int ww = width - 1;
        int hh = height - 1;
        float x = 0, y = 0, d = 0, n = 0;
        int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
        WritableRaster targetRaster = target.getRaster();
        byte[] dataBuffer = ((DataBufferByte)targetRaster.getDataBuffer()).getData();
        int destIndex = 0;
        
        int dw = destWidth - 1;
        
        pixel[0] = getPixel(byteBuffer, pixel[0], 0, 0, width, height, hasAlpha);
        destIndex = setPixel(dataBuffer, pixel[0], destIndex, hasAlpha);
        for (int i = 1; i < dw; i++)
        {
            x = i * su;
            x1 = (int)x;
            x2 = x1 + 1;
            d = x2 - x;
            pixel[0] = getPixel(byteBuffer, pixel[0], x1, 0, width, height, hasAlpha);
            pixel[1] = getPixel(byteBuffer, pixel[1], x2, 0, width, height, hasAlpha);
            pixel[0] = mixedColors(d, pixel[0], pixel[1], hasAlpha);
            destIndex = setPixel(dataBuffer, pixel[0], destIndex, hasAlpha);
        }
        pixel[0] = getPixel(byteBuffer, pixel[0], ww, 0, width, height, hasAlpha);
        destIndex = setPixel(dataBuffer, pixel[0], destIndex, hasAlpha);
        
        int dH = destHeight - 1;
        for (int j = 1; j < dH; j++)
        {
            y = j * sv;
            y1 = (int)y;
            y2 = y1 + 1;
            n = y2 - y;
            pixel[0] = getPixel(byteBuffer, pixel[0], 0, y1, width, height, hasAlpha);
            pixel[1] = getPixel(byteBuffer, pixel[1], 0, y2, width, height, hasAlpha);
            pixel[0] = mixedColors(n, pixel[0], pixel[1], hasAlpha);
            destIndex = setPixel(dataBuffer, pixel[0], destIndex, hasAlpha);
            y1 = (int)(y + 0.5f);
            for (int i = 1; i < dw; i++)
            {
                x = i * su;
                x1 = (int)x;
                x2 = x1 + 1;
                d = x2 - x;
                pixel[0] = getPixel(byteBuffer, pixel[0], x1, y1, width, height, hasAlpha);
                pixel[1] = getPixel(byteBuffer, pixel[1], x2, y1, width, height, hasAlpha);
                pixel[2] = getPixel(byteBuffer, pixel[2], x1, y2, width, height, hasAlpha);
                pixel[3] = getPixel(byteBuffer, pixel[3], x2, y2, width, height, hasAlpha);
                pixel[0] = mixedColors_4(pixel, d, n, hasAlpha);
                destIndex = setPixel(dataBuffer, pixel[0], destIndex, hasAlpha);
            }
            y1 = y2 - 1;
            pixel[0] = getPixel(byteBuffer, pixel[0], ww, y1, width, height, hasAlpha);
            pixel[1] = getPixel(byteBuffer, pixel[1], ww, y2, width, height, hasAlpha);
            pixel[0] = mixedColors(n, pixel[0], pixel[1], hasAlpha);
            destIndex = setPixel(dataBuffer, pixel[0], destIndex, hasAlpha);
        }
        
        pixel[0] = getPixel(byteBuffer, pixel[0], 0, hh, width, height, hasAlpha);
        destIndex = setPixel(dataBuffer, pixel[0], destIndex, hasAlpha);
        for (int i = 1; i < dw; i++)
        {
            x = i * su;
            x1 = (int)x;
            x2 = x1 + 1;
            d = x2 - x;
            pixel[0] = getPixel(byteBuffer, pixel[0], x1, hh, width, height, hasAlpha);
            pixel[1] = getPixel(byteBuffer, pixel[1], x2, hh, width, height, hasAlpha);
            pixel[0] = mixedColors(d, pixel[0], pixel[1], hasAlpha);
            destIndex = setPixel(dataBuffer, pixel[0], destIndex, hasAlpha);
        }
        pixel[0] = getPixel(byteBuffer, pixel[0], ww, hh, width, height, hasAlpha);
        destIndex = setPixel(dataBuffer, pixel[0], destIndex, hasAlpha);
        return target;
	}
	
	protected static final int[] getPixel(byte[] byteBuffer, int[] pixel, int x, int y, int w,
	        int h, boolean hasAlpha)
	    {
	        if (x < 0)
	        {
	            x = 0;
	        }
	        if (y < 0)
	        {
	            y = 0;
	        }
	        if (x >= w)
	        {
	            x = w - 1;
	        }
	        if (y >= h)
	        {
	            y = h - 1;
	        }
	        if (pixel == null)
	        {
	            pixel = new int[hasAlpha ? 4 : 3];
	        }
	        if (hasAlpha)
	        {
	            int index = 4 * (y * w + x);
	            pixel[3] = byteBuffer[index++] & 0xFF;
	            if(pixel[3] == 0)
	            {
	                pixel[2] = pixel[1] = pixel[0] = 255;
	                index += 3;
	            }
	            else
	            {
	                pixel[2] = byteBuffer[index++] & 0xFF;
	                pixel[1] = byteBuffer[index++] & 0xFF;
	                pixel[0] = byteBuffer[index++] & 0xFF;
	            }
	        }
	        else
	        {
	            int index = (y * w + x) * 3;
	            pixel[2] = byteBuffer[index++] & 0xFF;
	            pixel[1] = byteBuffer[index++] & 0xFF;
	            pixel[0] = byteBuffer[index++] & 0xFF;
	        }
	        return pixel;
	    }
	
	protected static final int[] getPixel(int[] intBuffer, int[] pixel, int x, int y, int w,
	        int h, boolean hasAlpha)
	    {
	        if (x < 0)
	        {
	            x = 0;
	        }
	        if (y < 0)
	        {
	            y = 0;
	        }
	        if (x >= w)
	        {
	            x = w - 1;
	        }
	        if (y >= h)
	        {
	            y = h - 1;
	        }
	        if (pixel == null)
	        {
	            pixel = new int[hasAlpha ? 4 : 3];
	        }
	        int index = y * w + x;
	        pixel[2] = (intBuffer[index] >> 16) & 0xFF;
	        pixel[1] = (intBuffer[index] >> 8) & 0xFF;
	        pixel[0] = intBuffer[index] & 0xFF;
	        if(hasAlpha)
	        {
	            pixel[3] = (intBuffer[index] >> 24) & 0xFF;
	            if (pixel[3] == 0)
	            {
	                pixel[2] = pixel[1] = pixel[0] = -1;
	            }
	        }        
	        return pixel;
	    }
	
	   protected static final int setPixel(byte[] dataBuffer, int[] pixel, int index, boolean hasAlpha)
	    {
	        if (hasAlpha)
	        {
	            dataBuffer[index++] = (byte)pixel[3];
	        }
	        dataBuffer[index++] = (byte)pixel[2];
	        dataBuffer[index++] = (byte)pixel[1];
	        dataBuffer[index++] = (byte)pixel[0];
	        return index;
	    }
	   
	   private final static int[] mixedColors(float d, int[] pixel1, int[] pixel2, boolean hasAlpha)
	    {
	        float b = 1 - d;
	        if (hasAlpha)
	        {
	            pixel1[3] = (int)(pixel1[3] * d + pixel2[3] * b);
	        }
	        pixel1[0] = (int)(pixel1[0] * d + pixel2[0] * b);
	        pixel1[1] = (int)(pixel1[1] * d + pixel2[1] * b);
	        pixel1[2] = (int)(pixel1[2] * d + pixel2[2] * b);
	        return pixel1;
	    }
	   private final static int[] mixedColors_4(int[][] pixel, float d, float n, boolean hasAlpha)
	    {
	        float ds = 1 - d;
	        float ns = 1 - n;
	        pixel[0][0] = (int)(pixel[0][0] * d * n + pixel[1][0] * ds * n + pixel[2][0] * d * ns + pixel[3][0]
	            * ns * ds);
	        pixel[0][1] = (int)(pixel[0][1] * d * n + pixel[1][1] * ds * n + pixel[2][1] * d * ns + pixel[3][1]
	            * ns * ds);
	        pixel[0][2] = (int)(pixel[0][2] * d * n + pixel[1][2] * ds * n + pixel[2][2] * d * ns + pixel[3][2]
	            * ns * ds);
	        if (hasAlpha)
	        {
	            pixel[0][3] = (int)(pixel[0][3] * n * d + pixel[1][3] * ds * n + pixel[2][3] * d * ns + pixel[3][3]
	                * ns * ds);
	        }
	        return pixel[0];
	    }
	public static void main(String[] args) throws IOException {
		TextureComponent1 tc = new TextureComponent1();
		JFrame jf = new JFrame("test");
		jf.setSize(500, 500);
		jf.add(tc);
		jf.setVisible(true);
	}

}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Issue is reproducible on Ubuntu. Debugging to resolve this issue.
18-04-2018

Reported with JDK 8u161 Ubuntu 16.04 LTS Filling the texture with a zoomed picture cause an Internal exception - Exception in thread "AWT-EventQueue-0" java.lang.InternalError: Surface not cachable Checked this with the reported as well as ea versions and could confirm the issue as reported. Results: ======= 7u80: Fail 8: Fail 8u161: Fail 10: Fail 11 ea b09: Fail =========================================================================================== $ java -jar demo-InternalError.jar Exception in thread "AWT-EventQueue-0" java.lang.InternalError: Surface not cachable at java.desktop/sun.java2d.xr.XRPaints$XRTexture.getAccSrcSurface(XRPaints.java:217) at java.desktop/sun.java2d.xr.XRPaints$XRTexture.isPaintValid(XRPaints.java:230) at java.desktop/sun.java2d.xr.XRPaints.isValid(XRPaints.java:75) at java.desktop/sun.java2d.xr.XRSurfaceData.getMaskFill(XRSurfaceData.java:205) at java.desktop/sun.java2d.SurfaceData.validatePipe(SurfaceData.java:631) at java.desktop/sun.java2d.xr.XRSurfaceData.validatePipe(XRSurfaceData.java:123) at java.desktop/sun.java2d.SunGraphics2D.validatePipe(SunGraphics2D.java:447) at java.desktop/sun.java2d.pipe.ValidatePipe.validate(ValidatePipe.java:55) at java.desktop/sun.java2d.pipe.ValidatePipe.fill(ValidatePipe.java:159) at java.desktop/sun.java2d.SunGraphics2D.fill(SunGraphics2D.java:2528) at demo1.TextureComponent1.paintComponent(TextureComponent1.java:56) .................................. ........................................ ============================================================================================ This issue seems restricted to Linux (Ubuntu) only and work fine when checked in MAC OS X 10.13.1 and Windows 10. To verify, run the attached test case.
17-04-2018