Skip to content
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

Use linefeed directly to avoid platform dependent code #454

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

elharo
Copy link
Contributor

@elharo elharo commented Nov 9, 2024

This plugin seems to have a lot of usage of System.lineSeparator that produces platform dependent output and logs. These days I think pretty much every terminal on every platform should work with a simple \n and when the log goes anywhere other than a terminal then \n works better.

@elharo elharo marked this pull request as ready for review November 12, 2024 11:23
Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mke assumptions about a target.

Copy link
Member

@slawekjaranowski slawekjaranowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a benefit of it ... but can introduce a problems

@elharo
Copy link
Contributor Author

elharo commented Dec 4, 2024

The benefit is that the code does exactly the same thing and produces the same output on different platforms. This is especially important when writing files since files are not necessarily read on the same platform where they're written.

It's also simpler to write \n instead of System.lineSeparator(). Lines are shorter and it's less code to read.

@elharo
Copy link
Contributor Author

elharo commented Dec 5, 2024

For example, consider this fragment from JavadocUtiltest:

        // Other tests
        version = "java full version \"1.5.0_07-164\"" + System.getProperty("line.separator");
        assertEquals("1.5.0", JavadocUtil.extractJavadocVersion(version));

        version = System.getProperty("line.separator") + "java full version \"1.5.0_07-164\"";
        assertEquals("1.5.0", JavadocUtil.extractJavadocVersion(version));

        version = System.getProperty("line.separator") + "java full version \"1.5.0_07-164\""
                + System.getProperty("line.separator");
        assertEquals("1.5.0", JavadocUtil.extractJavadocVersion(version));

        version = "java full" + System.getProperty("line.separator") + " version \"1.5.0_07-164\"";
        assertEquals("1.5.0", JavadocUtil.extractJavadocVersion(version));

Here we test different strings depending on which platform the test runs on. We should instead run the same tests on all platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants