question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add checkstyle rules for List.of() / Set.of() / Map.of()

See original GitHub issue

We decided to not use List.of(), Set.of() and Map.of(), preferring Collections.emptyList(), etc. We should have a checkstyle rule to prevent creeping them accidentally in the codebase. Note that we only want to prohibit the non-argument versions, using List.of(a) etc. is fine.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
wilkinsonacommented, Aug 3, 2022

@dreis2211 We’re only disallowing the use of the zero-argument of() methods. List.of(a), Set.of(a, b), and so on will be permitted and we’re already making some use of those methods.

1reaction
mbhavecommented, Aug 3, 2022

@dreis2211 We discussed this on the team call today and decided that Collections.emptyList() was more explicit than List.of() for creating empty lists. However, we might decide to change this in the future because there is the consistency argument in favor of List.of(). For #28174, #28175 and #28178, we’ve decided to put those on hold for now. We won’t be doing a blanket replacement across the entire codebase but will approach it piecemeal for new usages. List.of()/Set.of()/Map.of() throw an NPE on contains(null) and will require closer examination than just replacing all occurrences of the Collections methods.

Read more comments on GitHub >

github_iconTop Results From Across the Web

checkstyle – Configuration - SourceForge
A Checkstyle configuration specifies which modules to plug in and apply to Java source files. Modules are structured in a tree whose root...
Read more >
Imports - checkstyle
Checks that the groups of import declarations appear in the order specified by the user. If there is an import but its group...
Read more >
Coding - checkstyle
Covariant equals() - method that is similar to equals(Object) , but with a covariant parameter type (any subtype of Object).
Read more >
Naming Conventions - checkstyle
public class MyTest { public void myTest() { try { // . ... Checks identifiers with a pattern for a set of illegal...
Read more >
Whitespace - checkstyle
Checks for empty line separators before package, all import ... public class Test { public Test() { // OK super(); // OK }...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found