Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private void handleSwitch(ExpressionTree expression, List<? extends CaseTree> ca
.filter(unused -> getFixer(withoutParens, subState).isPresent())
.ifPresent(
e ->
// NOTE: This fix is possibly too big: you can write `case null, default ->`.
// NOTE: user ->`.
state.reportMatch(describeMatch(caseTree, SuggestedFix.delete(caseTree))));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private static String suggestedSingleLetter(String id, Tree tree) {
// T -> T2
// T2 -> T3
// T -> T4 (if T2 and T3 already exist)
// TODO(user) : combine this method with TypeParameterShadowing.replacementTypeVarName
// TODO(siyuanl) : combine this method with TypeParameterShadowing.replacementTypeVarName
private static String firstLetterReplacementName(String name, List<String> superTypeVars) {
String firstLetterOfBase = Character.toString(name.charAt(0));
int typeVarNum = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2019 The Error Prone Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.errorprone.bugpatterns.nullness;

import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
import static com.google.errorprone.fixes.SuggestedFix.emptyFix;

import com.google.common.cache.CacheLoader;
import com.google.errorprone.BugPattern;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.fixes.SuggestedFix;
import com.sun.source.tree.ExpressionTree;

/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(summary = "The result of CacheLoader#load must be non-null.", severity = WARNING)
public final class CacheLoaderNull extends AbstractAsyncTypeReturnsNull {
public CacheLoaderNull() {
super(CacheLoader.class);
}

@Override
protected SuggestedFix provideFix(ExpressionTree tree) {
// The default suggestion is immediateFuture(null), which doesn't make sense for CacheLoader.
return emptyFix();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.bugpatterns.BugPatternNaming;
import com.google.errorprone.bugpatterns.ByteBufferBackingArray;
import com.google.errorprone.bugpatterns.CacheLoaderNull;
import com.google.errorprone.bugpatterns.CannotMockFinalClass;
import com.google.errorprone.bugpatterns.CannotMockMethod;
import com.google.errorprone.bugpatterns.CanonicalDuration;
Expand Down Expand Up @@ -579,6 +578,7 @@
import com.google.errorprone.bugpatterns.nullness.AddNullMarkedToPackageInfo;
import com.google.errorprone.bugpatterns.nullness.AsyncCallableReturnsNull;
import com.google.errorprone.bugpatterns.nullness.AsyncFunctionReturnsNull;
import com.google.errorprone.bugpatterns.nullness.CacheLoaderNull;
import com.google.errorprone.bugpatterns.nullness.DereferenceWithNullBranch;
import com.google.errorprone.bugpatterns.nullness.EqualsBrokenForNull;
import com.google.errorprone.bugpatterns.nullness.EqualsMissingNullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.errorprone.bugpatterns;
package com.google.errorprone.bugpatterns.nullness;

import com.google.errorprone.CompilationTestHelper;
import org.junit.Test;
Expand Down Expand Up @@ -45,6 +45,13 @@ public String load(String key) {
return null;
}
};
new CacheLoader<String, String>() {
@Override
public String load(String key) {
// BUG: Diagnostic contains:
return key.equals("") ? null : key;
}
};
abstract class MyCacheLoader extends CacheLoader<String, String> {}
new MyCacheLoader() {
@Override
Expand Down Expand Up @@ -92,7 +99,7 @@ public String get() {
return null;
}
}
;

return "";
}
};
Expand Down
Loading