JDK-6486887 : (prefs) 'Unknown attribute indent-number' using XML prefs w/ Saxon
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2006-10-26
  • Updated: 2010-04-03
  • Resolved: 2006-11-30
Related Reports
Duplicate :  
Description
Run the following program using JDK 6 b102 on Unix after adding saxon8.jar (unpacked from http://prdownloads.sourceforge.net/saxon/saxonb8-8j.zip?download) to the classpath:

---%<---
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
public class IndentNumberBug {
    public static void main(String[] args) throws BackingStoreException {
        Preferences p = Preferences.userRoot().node("test/node");
        p.removeNode();
        p = Preferences.userRoot().node("test/node");
        p.put("k", "v");
        p.flush();
    }
}
---%<---

You will see:

---%<---
Exception in thread "main" java.util.prefs.BackingStoreException: java.lang.IllegalArgumentException: Unknown attribute 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 java.util.prefs.FileSystemPreferences.flush(FileSystemPreferences.java:807)
        at IndentNumberBug.main(IndentNumberBug.java:9)
Caused by: java.lang.IllegalArgumentException: Unknown attribute indent-number
        at net.sf.saxon.Configuration.setConfigurationProperty(Configuration.java:2260)
        at net.sf.saxon.TransformerFactoryImpl.setAttribute(TransformerFactoryImpl.java:342)
        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)
        ... 12 more
Oct 25, 2006 3:29:13 PM java.util.prefs.FileSystemPreferences syncWorld
WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: java.lang.IllegalArgumentException: Unknown attribute indent-number
---%<---

Worse, if you comment out the call to flush(), you get an unhelpful message (took me a while to track this down to its source!) and no stack trace:

---%<---
Oct 25, 2006 3:34:43 PM java.util.prefs.FileSystemPreferences syncWorld
WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: java.lang.IllegalArgumentException: Unknown attribute indent-number
---%<---

Comments
SUGGESTED FIX XmlSupport.writeDoc is calling tf.setAttribute("indent-number", new Integer(2)); assuming that it will be interpreted by the currently selected XSLT processor. This cannot be assumed; should use try { tf.setAttribute("indent-number", 2); } catch (IllegalArgumentException e) { // ignore, file will still be correct } Also FileSystemPreferences.syncWorld is logging improperly: } catch(BackingStoreException e) { getLogger().warning("Couldn't flush user prefs: " + e); } should be } catch (BackingStoreException e) { getLogger().log(Level.WARNING, "Could not flush user prefs", e); } to preserve the stack trace. Similarly a few lines below. BTW: FSP.chmod is probably obsoleted by File.set{Read,Writ}able.
26-10-2006

WORK AROUND Perhaps temporarily setting thread context class loader to bootstrap loader for the duration of the work with Preferences, to force usage of Xalan-XSLTC. Not tested.
26-10-2006