New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line separator System property fails #114

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

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

This comment has been minimized.

Show comment
Hide comment
@rolfl

rolfl Apr 11, 2013

Collaborator

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.

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

This comment has been minimized.

Show comment
Hide comment
@rolfl

rolfl Apr 11, 2013

Collaborator

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.

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 added a commit that referenced this issue Apr 12, 2013

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.

@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