Line separator System property fails #114

Closed
gpolet opened this Issue Apr 11, 2013 · 2 comments

Projects

None yet

2 participants

@gpolet
gpolet commented Apr 11, 2013

Using the system property JDOMConstants.JDOM2_PROPERTY_LINE_SEPARATOR does not work and creates faulty documents with the value of the property instead of the value of the LineSeparator enum.

Calling System.setProperty(JDOMConstants.JDOM2_PROPERTY_LINE_SEPARATOR, "SYSTEM"); before anything else should make the system line separator the default line separator when serializing. Instead, the default line separator is initialized to the String value "SYSTEM".

Here is a test that currently fails with version 2.0.4 of JDom (Java 6 or Java 7):

package org.flexo.model;

import junit.framework.Assert;

import org.jdom2.JDOMConstants;
import org.jdom2.output.LineSeparator;
import org.junit.Test;

public class TestJDomLineSeparator {

    @Test
    public void testLineSeparatorFromSystemProperty() {
        System.setProperty(JDOMConstants.JDOM2_PROPERTY_LINE_SEPARATOR, "SYSTEM");
        Assert.assertEquals(System.getProperty("line.separator"), LineSeparator.DEFAULT.value());
    }
}

It seems that calling final LineSeparator sep = Enum.valueOf(LineSeparator.class, prop); throws an IllegalArgumentException when called during the initialization of the enum. The exception is silently caught and the system property is immediately returned (this last part does not make sense).

@rolfl
Collaborator
rolfl commented Apr 11, 2013

Hmmm... I have tested the code. I wonder whether this code changed in a later version of Java.... but, I agree. it is broken right now.

Stil investigating.

@rolfl
Collaborator
rolfl commented Apr 11, 2013

Oh, and the reason the exception is silently ignored is for those times when you want your separator to be 'jinglebells', or some value that is not the defined name for a constant.

@rolfl rolfl added a commit that referenced this issue Apr 12, 2013
@rolfl rolfl Fixes #114 - line separator fails to initialize.
COde was trying to be too clever about value duplication. As a result, the enumberator values were trying to reference each other before they were initialized.
Fix is to just do things simpler. Much simpler.
4d5e1e1
@rolfl rolfl added a commit that closed this issue Apr 14, 2013
@rolfl rolfl Fixes #114 - line separator fails to initialize.
COde was trying to be too clever about value duplication. As a result, the enumberator values were trying to reference each other before they were initialized.
Fix is to just do things simpler. Much simpler.
53c87d7
@rolfl rolfl closed this in 53c87d7 Apr 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment