JDK-6519088 : (prefs) Preferences API depends on indentation support of underlying XML transformer
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2007-01-30
  • Updated: 2011-02-16
  • Resolved: 2008-03-13
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_01-ea"
Java(TM) SE Runtime Environment (build 1.6.0_01-ea-b01)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_01-ea-b01, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux xmart 2.6.19-gentoo-r4 #1 SMP Wed Jan 17 17:04:23 MSK 2007 i686 Genuine Intel(R) CPU           T2500  @ 2.00GHz GenuineIntel GNU/Linux
Linux localhost 2.6.8-1.520smp #1 SMP Sat Aug 14 06:27:12 EDT 2004 i686 i686 i386 GNU/Linux
Linux localhost 2.6.18-1.2798.fc6 #1 SMP Mon Oct 16 14:39:22 EDT 2006 x86_64 x86_64 x86_64 GNU/Linux
Linux localhost 2.6.15-1.2054_FC5 #1 SMP Tue Mar 14 15:48:20 EST 2006 x86_64 x86_64 x86_64 GNU/Linux
Linux localhost 2.6.9-22.0.2.ELsmp #1 SMP Tue Jan 17 06:12:06 CST 2006 x86_64 x86_64 x86_64 GNU/Linux
Linux localhost 2.6.5-7.97-smp #1 SMP Fri Jul 2 14:21:59 UTC 2004 x86_64 x86_64 x86_64 GNU/Linux

(Gentoo, CentOS, SLES, Debian, Fedora Core 5/6)

this bug is OS-agnostic, BUT jdk-6u1-b1 x86 build works while x86_64 doesn't

EXTRA RELEVANT SYSTEM CONFIGURATION :
Resin 3.0.21 - uses its own SAX and XSLT engines

A DESCRIPTION OF THE PROBLEM :
preferences API depends on XSLT-engine's ability to indent output, which may or may not be present, but it MUST NOT stop preferences api writing prefs file to disk.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
put http://mirrors.ibiblio.org/pub/mirrors/maven2/xalan/xalan/2.7.0/xalan-2.7.0.jar
on classpath and try running following class:

public class Main {
  public static void main(String[] args) throws BackingStoreException {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);
    prefs.putDouble("test", Math.random());
    prefs.sync();
  }
}


ACTUAL -
Exception in thread "main" java.util.prefs.BackingStoreException: java.lang.IllegalArgumentException: Not supported: indent-number
	at java.util.prefs.FileSystemPreferences$8.run(FileSystemPreferences.java:615)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.util.prefs.FileSystemPreferences.writeBackCache(FileSystemPreferences.java:600)
	at java.util.prefs.FileSystemPreferences.syncSpiPrivileged(FileSystemPreferences.java:784)
	at java.util.prefs.FileSystemPreferences.access$2300(FileSystemPreferences.java:33)
	at java.util.prefs.FileSystemPreferences$13.run(FileSystemPreferences.java:754)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.util.prefs.FileSystemPreferences.syncSpi(FileSystemPreferences.java:752)
	at java.util.prefs.AbstractPreferences.sync2(AbstractPreferences.java:1317)
	at java.util.prefs.AbstractPreferences.sync(AbstractPreferences.java:1308)
	at java.util.prefs.FileSystemPreferences.sync(FileSystemPreferences.java:731)
	at Main.main(Main.java:9)
Caused by: java.lang.IllegalArgumentException: Not supported: indent-number
	at org.apache.xalan.processor.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:574)
	at java.util.prefs.XmlSupport.writeDoc(XmlSupport.java:247)
	at java.util.prefs.XmlSupport.exportMap(XmlSupport.java:333)
	at java.util.prefs.FileSystemPreferences$8.run(FileSystemPreferences.java:607)
	... 11 more


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.util.prefs.BackingStoreException: java.lang.IllegalArgumentException: Not supported: indent-number
	at java.util.prefs.FileSystemPreferences$8.run(FileSystemPreferences.java:615)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.util.prefs.FileSystemPreferences.writeBackCache(FileSystemPreferences.java:600)
	at java.util.prefs.FileSystemPreferences.syncSpiPrivileged(FileSystemPreferences.java:784)
	at java.util.prefs.FileSystemPreferences.access$2300(FileSystemPreferences.java:33)
	at java.util.prefs.FileSystemPreferences$13.run(FileSystemPreferences.java:754)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.util.prefs.FileSystemPreferences.syncSpi(FileSystemPreferences.java:752)
	at java.util.prefs.AbstractPreferences.sync2(AbstractPreferences.java:1317)
	at java.util.prefs.AbstractPreferences.sync(AbstractPreferences.java:1308)
	at java.util.prefs.FileSystemPreferences.sync(FileSystemPreferences.java:731)
	at Main.main(Main.java:9)
Caused by: java.lang.IllegalArgumentException: Not supported: indent-number
	at org.apache.xalan.processor.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:574)
	at java.util.prefs.XmlSupport.writeDoc(XmlSupport.java:247)
	at java.util.prefs.XmlSupport.exportMap(XmlSupport.java:333)
	at java.util.prefs.FileSystemPreferences$8.run(FileSystemPreferences.java:607)
	... 11 more


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Main {
  public static void main(String[] args) throws BackingStoreException {
    Preferences prefs = Preferences.userNodeForPackage(Main.class);
    prefs.putDouble("test", Math.random());
    prefs.sync();
  }
}

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

CUSTOMER SUBMITTED WORKAROUND :
patch java.uril.prefs.XmlSupport.java:

    private static final void writeDoc(Document doc, OutputStream out)
        throws IOException
    {
        try {
            TransformerFactory tf = TransformerFactory.newInstance();
++            try {
                tf.setAttribute("indent-number", new Integer(2));
++            } catch (Exception e) {
++                // swallow
++            }
            Transformer t = tf.newTransformer();
            t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId());
++            try {
                t.setOutputProperty(OutputKeys.INDENT, "yes");
++            } catch (Exception e) {
++                // swallow
++            }
	    //Transformer resets the "indent" info if the "result" is a StreamResult with
	    //an OutputStream object embedded, creating a Writer object on top of that
	    //OutputStream object however works.
            t.transform(new DOMSource(doc),
			new StreamResult(new BufferedWriter(new OutputStreamWriter(out, "UTF-8"))));
        } catch(TransformerException e) {
            throw new AssertionError(e);
        }
    }

Comments
EVALUATION This is the dup of 6396599, which has been fixed long time ago in the on-going release JDK7. 6396599 has also been committed to backport the same fix to 6u release 6u10 as well. Closed as 6396599.
13-03-2008