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

[java] New rule for simplifiable system property access #2132

Open
oowekyala opened this issue Nov 26, 2019 · 7 comments
Open

[java] New rule for simplifiable system property access #2132

oowekyala opened this issue Nov 26, 2019 · 7 comments
Labels
a:new-rule Proposal to add a new built-in rule

Comments

@oowekyala
Copy link
Member

Rule name: TBD

Add a rule to convert calls to System.getProperty("line.separator") to use System.lineSeparator() since that is the reason the method was added See JDK-6900043.

Originally posted by @Sthornton12 in #1993 (comment)

See also File.separator/ File.separatorChar vs System.getProperty("file.separator"), although those don't have an @since

@linusjf
Copy link

linusjf commented Nov 27, 2019

UsePerformantProperties if you're using the rule for both properties. UsePerformantLineSeparator and UsePerformantFileSeparator otherwise. Or just PerformantXXX.

@oowekyala
Copy link
Member Author

I don't think this is performance-related at all... Mostly this is about verbosity and security, as the JDK bug report explains. Maybe UseSystemPropertyShorthands?

@linusjf
Copy link

linusjf commented Nov 29, 2019

https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6264243

Refer above.

Implementation of lineSeparator() in OpenJDK 7:

    public static String lineSeparator() {
        return lineSeparator;
    }

    private static String lineSeparator;

http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/cf44386c8fe3/src/share/classes/java/lang/System.java

@oowekyala
Copy link
Member Author

Thanks for linking this ticket. I get that the performance is likely better. But I still think the performance concern should be secondary and not in the name of the rule. The other concerns seem more universal (Correctness/Ease of use & cross-platform development/Readibility/Security), whereas "Performance" depends on JDK implementation, and how hot the code is.

@linusjf
Copy link

linusjf commented Nov 29, 2019 via email

@oowekyala
Copy link
Member Author

How about DeprecateSystemPropertyCalls or ReplaceSystemPropertyCalls?

The second one seems very fine to me.

You have StringBuffer and StringBuilder rules. Don't those improve performance? Similarly, deprecation of Vector usage.

Yes, those do improve performance and that's about all they do.

By contrast, this rule's most important contribution is IMO not improving performance. That's just a happy side effect, that in most cases will be next to irrelevant.

@linusjf
Copy link

linusjf commented Dec 1, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:new-rule Proposal to add a new built-in rule
Projects
None yet
Development

No branches or pull requests

2 participants