JDK-8066132 : BufferedImage::getPropertyNames() always returns null
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8u25,8u40
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: other
  • CPU: x86
  • Submitted: 2014-11-13
  • Updated: 2015-09-29
  • Resolved: 2015-01-17
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
8u60Fixed 9 b52Fixed
Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b16, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
OS-X 10.9.4 (but think this affects all versions)

A DESCRIPTION OF THE PROBLEM :
BufferedImage::getPropertyNames() always returns null
----------------------------

From the source of BufferedImage I see:

    public String[] getPropertyNames() {
         return null;
    }

Whereas the implementation of getProperty(String name) is:

    public Object getProperty(String name) {
        if (name == null) {
            throw new NullPointerException("null property name is not allowed");
        }
        if (properties == null) {
            return java.awt.Image.UndefinedProperty;
        }
        Object o = properties.get(name);
        if (o == null) {
            o = java.awt.Image.UndefinedProperty;
        }
        return o;
    }

This means you can create a BufferedImage with properties but there is no way to interrogate them to establish what properties a BufferedImage has.

getPropertyNames() should be fixed t something like:

    public String[] getPropertyNames() {
        if (properties == null) {
            return null;
        }
        return properties.entrySet().toArray(new String[0]);    }
     }

ADDITIONAL REGRESSION INFORMATION: 
Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b16, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create BufferedImage with some Properties.
Try listing the property names with BufferedImages::getPropertyNames()

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
getPropertyNames() should return String[] with property names
ACTUAL -
getPropertyNames() returns null

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package javabugs;

import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.util.Properties;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author michaelellis
 */
public class JavaBugsTest {

    public JavaBugsTest() {
    }

    @Test
    public void testBufferedImageProperties() {

        // Create BufferedImage easy way to create the Raster and ColorModel used later
        BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
        WritableRaster raster = bi.getData().createCompatibleWritableRaster();
        ColorModel cm = bi.getColorModel();

        // Create properties
        Properties props = new Properties();
        props.setProperty("Animal", "Cat");
        props.setProperty("Fruit", "Apple");

        // Create new BufferedImage WITH Raster, ColorModel AND Properties
        BufferedImage bufferedImage = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), props);

        // Check the properties are there
        assertEquals("Cat", bufferedImage.getProperty("Animal"));
        assertEquals("Apple", bufferedImage.getProperty("Fruit"));

        // List the Properties - OOPS!
        assertNotNull(bufferedImage.getPropertyNames());
    }

}

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

CUSTOMER SUBMITTED WORKAROUND :
No real work around.

SUPPORT :
YES


Comments
is it an issue affected 8 GA as well?
28-11-2014

Tested this with JDK 8u25 and 8u40 and could reproduce the issue.
28-11-2014