[prone] fix warning `StaticImport`, `NonStaticImport`

Open
#2,743 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
tooling

Research direction

Start by running the build that produced these Error Prone diagnostics and review the mentioned files, including LibPreconditions.java, MoreIterables.java, FileSignature.java, Formatter.java, and LineEnding.java. Use the StaticImport and NonStaticImport references as the initial scope, then verify the selected warnings no longer appear in the build output.

Written by the indexing model from the issue text.

Description

Following the build, StaticImport has the potential to remove a lot of warnings, improving focus on the truly important stuff by moving the class context into oblivion using the static import.

These would again reduce the log significantly, making more space for better clarity:

    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'requireNonNull(elements);'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LibPreconditions.java:27: Note: [StaticImport] Identifier should be statically imported
			Objects.requireNonNull(element);
			       ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'requireNonNull(element);'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/MoreIterables.java:43: Note: [StaticImport] Identifier should be statically imported
		return toSortedSet(raw, Comparator.naturalOrder());
		                                  ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'return toSortedSet(raw, naturalOrder());'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/FileSignature.java:106: Note: [LexicographicalAnnotationListing] Sort annotations lexicographically where possible
		@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
		^
    (see https://error-prone.picnic.tech/bugpatterns/LexicographicalAnnotationListing)
  Did you mean '@Nullable'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/FileSignature.java:137: Note: [StaticImport] Identifier should be statically imported
		return Collections.unmodifiableList(files);
		                  ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'return unmodifiableList(files);'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/FormatterStepEqualityOnStateSerialization.java:63: warning: [EqualsGetClass] Prefer instanceof to getClass when implementing Object#equals.
	public boolean equals(Object o) {
	               ^
    (see https://errorprone.info/bugpattern/EqualsGetClass)
  Did you mean 'if (!(o instanceof FormatterStepEqualityOnStateSerialization)) {'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/FormatterStepSerializationRoundtrip.java:125: Note: [StaticImport] Identifier should be statically imported
			return original != null ? original : Objects.requireNonNull(cleaned, "how is clean null if this has been serialized?");
			                                            ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'return original != null ? original : requireNonNull(cleaned, "how is clean null if this has been serialized?");'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/FormatterStepSerializationRoundtrip.java:129: warning: [EqualsGetClass] Prefer instanceof to getClass when implementing Object#equals.
		public boolean equals(Object o) {
		               ^
    (see https://errorprone.info/bugpattern/EqualsGetClass)
  Did you mean 'if (!(o instanceof HackClone)) {'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java:47: Note: [StaticImport] Identifier should be statically imported
		this.lineEndingsPolicy = Objects.requireNonNull(lineEndingsPolicy, "lineEndingsPolicy");
		                                ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'this.lineEndingsPolicy = requireNonNull(lineEndingsPolicy, "lineEndingsPolicy");'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java:48: Note: [StaticImport] Identifier should be statically imported
		this.encoding = Objects.requireNonNull(encoding, "encoding");
		                       ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'this.encoding = requireNonNull(encoding, "encoding");'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java:119: Note: [StaticImport] Identifier should be statically imported
		Objects.requireNonNull(unix, "unix");
		       ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'requireNonNull(unix, "unix");'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java:120: Note: [StaticImport] Identifier should be statically imported
		Objects.requireNonNull(file, "file");
		       ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'requireNonNull(file, "file");'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java:152: warning: [Slf4jLoggerDeclaration] SLF4J logger declarations should follow established best-practices
	private static final Logger LOGGER = LoggerFactory.getLogger(Formatter.class);
	                            ^
    (see https://error-prone.picnic.tech/bugpatterns/Slf4jLoggerDeclaration)
  Did you mean 'LOG.error("Step '{}' found problem in '{}':\n{}", formatter.getSteps().get(i).getName(), file.getName(), exception.getMessage(), exception);'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java:165: Note: [StaticImport] Identifier should be statically imported
		Objects.requireNonNull(unix, "unix");
		       ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'requireNonNull(unix, "unix");'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java:166: Note: [StaticImport] Identifier should be statically imported
		Objects.requireNonNull(file, "file");
		       ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'requireNonNull(file, "file");'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java:223: Note: [LexicographicalAnnotationListing] Sort annotations lexicographically where possible
	@SuppressWarnings("rawtypes")
	^
    (see https://error-prone.picnic.tech/bugpatterns/LexicographicalAnnotationListing)
  Did you mean '@Override'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java:242: warning: [ReferenceEquality] Comparison using reference equality instead of value equality
		if (file == Formatter.NO_FILE_SENTINEL) {
		         ^
    (see https://errorprone.info/bugpattern/ReferenceEquality)
  Did you mean 'if (Objects.equals(file, Formatter.NO_FILE_SENTINEL)) {' or 'if (file.equals(Formatter.NO_FILE_SENTINEL)) {'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/ValuePerStep.java:36: Note: [LexicographicalAnnotationListing] Sort annotations lexicographically where possible
	@Override
	^
    (see https://error-prone.picnic.tech/bugpatterns/LexicographicalAnnotationListing)
  Did you mean '@Nullable'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:38: warning: [InlineMeSuggester] This deprecated API looks inlineable. If you'd like the body of the API to be automatically inlined to its callers, please annotate it with @InlineMe. NOTE: the suggested fix makes the method final if it was not already.
		public Policy createPolicy() {
		              ^
    (see https://errorprone.info/bugpattern/InlineMeSuggester)
  Did you mean '@InlineMe(replacement = "super.createPolicy()")'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:37: Note: [LexicographicalAnnotationListing] Sort annotations lexicographically where possible
		@Override @Deprecated
		^
    (see https://error-prone.picnic.tech/bugpatterns/LexicographicalAnnotationListing)
  Did you mean '@Deprecated @Override'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:46: warning: [InlineMeSuggester] This deprecated API looks inlineable. If you'd like the body of the API to be automatically inlined to its callers, please annotate it with @InlineMe. NOTE: the suggested fix makes the method final if it was not already.
		public Policy createPolicy() {
		              ^
    (see https://errorprone.info/bugpattern/InlineMeSuggester)
  Did you mean '@InlineMe(replacement = "super.createPolicy()")'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:45: Note: [LexicographicalAnnotationListing] Sort annotations lexicographically where possible
		@Override @Deprecated
		^
    (see https://error-prone.picnic.tech/bugpatterns/LexicographicalAnnotationListing)
  Did you mean '@Deprecated @Override'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:64: Note: [StaticImport] Identifier should be statically imported
		Objects.requireNonNull(projectDir, "projectDir");
		       ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'requireNonNull(projectDir, "projectDir");'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:65: Note: [StaticImport] Identifier should be statically imported
		Objects.requireNonNull(toFormat, "toFormat");
		       ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'requireNonNull(toFormat, "toFormat");'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:86: warning: [StatementSwitchToExpressionSwitch] This statement switch can be converted to a new-style arrow switch
		switch (this) {
		^
    (see https://errorprone.info/bugpattern/StatementSwitchToExpressionSwitch)
  Did you mean 'return switch (this) {' or 'switch (this) {'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:117: Note: [StaticImport] Identifier should be statically imported
            try (Reader reader = new FileReader(file, StandardCharsets.US_ASCII)) {
                                                                      ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'try (Reader reader = new FileReader(file, US_ASCII)) {'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:160: warning: [MissingSummary] A summary fragment is required; consider using the value of the @see block as a summary fragment instead.
	 * @deprecated Using the system-native line endings to detect the windows operating system has turned out
	   ^
    (see https://google.github.io/styleguide/javaguide.html#s7.2-summary-fragment)
  Did you mean '*See {@link FileSignature#machineIsWin()}.'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:172: warning: [StatementSwitchToExpressionSwitch] This statement switch can be converted to a new-style arrow switch
		switch (this) {
		^
    (see https://errorprone.info/bugpattern/StatementSwitchToExpressionSwitch)
  Did you mean 'return switch (this) {' or 'switch (this) {'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/LineEnding.java:189: Note: [StaticImport] Identifier should be statically imported
			Objects.requireNonNull(file);
			       ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'requireNonNull(file);'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java:226: Note: [StaticImport] Identifier should be statically imported
			return new String(stdOut, StandardCharsets.UTF_8);
			                                          ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'return new String(stdOut, UTF_8);'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java:230: Note: [StaticImport] Identifier should be statically imported
			return new String(stdErr, StandardCharsets.UTF_8);
			                                          ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)
  Did you mean 'return new String(stdErr, UTF_8);'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/ProcessRunner.java:263: warning: [StringSplitter] String.split(String) has surprising behavior
					String[] lines = string.replace("\r", "").split("\n");
					                                               ^
    (see https://errorprone.info/bugpattern/StringSplitter)
  Did you mean 'List<String> lines = Splitter.on('\n').splitToList(string.replace("\r", ""));'?
/Users/vincent.potucek/IdeaProjects/spotless/lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java:107: Note: [StaticImport] Identifier should be statically imported
			this.exe = Objects.requireNonNull(goExecutable);
			                  ^
    (see https://error-prone.picnic.tech/bugpatterns/StaticImport)

Dominant language
Java
Stars
5.7k
Forks
560
Avg merge
1d 13h
Merged PRs (30d)
43

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diffplug/spotless

All issues in diffplug/spotless

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.