Skip to content

Apply IntelliJ inspections to improve code quality #39259

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

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ private boolean isNodeWithName(Object candidate, String name) {
if ((node.name() instanceof QName qname) && name.equals(qname.getLocalPart())) {
return true;
}
if (name.equals(node.name())) {
return true;
}
return name.equals(node.name());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private Milestone determineMilestone(GitHubRepository repository) {
java.util.Optional<Milestone> matchingMilestone = milestones.stream()
.filter((milestone) -> milestone.getName().equals(getMilestone().get()))
.findFirst();
if (!matchingMilestone.isPresent()) {
if (matchingMilestone.isEmpty()) {
throw new InvalidUserDataException("Unknown milestone: " + getMilestone().get());
}
return matchingMilestone.get();
Expand Down Expand Up @@ -242,9 +242,9 @@ private boolean isAnUpgrade(Library library, DependencyVersion candidate) {
}

private boolean isNotProhibited(Library library, DependencyVersion candidate) {
return !library.getProhibitedVersions()
return library.getProhibitedVersions()
.stream()
.anyMatch((prohibited) -> prohibited.isProhibited(candidate.toString()));
.noneMatch((prohibited) -> prohibited.isProhibited(candidate.toString()));
}

private List<Library> matchingLibraries() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public boolean equals(Object obj) {
return false;
}
AbstractDependencyVersion other = (AbstractDependencyVersion) obj;
if (!this.comparableVersion.equals(other.comparableVersion)) {
return false;
}
return true;
return this.comparableVersion.equals(other.comparableVersion);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public int compareTo(DependencyVersion other) {

@Override
public boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots) {
if (!(candidate instanceof ReleaseTrainDependencyVersion)) {
if (!(candidate instanceof ReleaseTrainDependencyVersion candidateReleaseTrain)) {
return true;
}
ReleaseTrainDependencyVersion candidateReleaseTrain = (ReleaseTrainDependencyVersion) candidate;
int comparison = this.releaseTrain.compareTo(candidateReleaseTrain.releaseTrain);
if (comparison != 0) {
return comparison < 0;
Expand All @@ -88,10 +87,9 @@ private boolean isSnapshot() {

@Override
public boolean isSnapshotFor(DependencyVersion candidate) {
if (!isSnapshot() || !(candidate instanceof ReleaseTrainDependencyVersion)) {
if (!isSnapshot() || !(candidate instanceof ReleaseTrainDependencyVersion candidateReleaseTrain)) {
return false;
}
ReleaseTrainDependencyVersion candidateReleaseTrain = (ReleaseTrainDependencyVersion) candidate;
return this.releaseTrain.equals(candidateReleaseTrain.releaseTrain);
}

Expand Down Expand Up @@ -127,10 +125,7 @@ public boolean equals(Object obj) {
return false;
}
ReleaseTrainDependencyVersion other = (ReleaseTrainDependencyVersion) obj;
if (!this.original.equals(other.original)) {
return false;
}
return true;
return this.original.equals(other.original);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ private boolean prohibited(ModuleVersionIdentifier id) {
if (group.equals("org.apache.geronimo.specs")) {
return true;
}
if (group.equals("com.sun.activation")) {
return true;
}
return false;
return group.equals("com.sun.activation");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ public CloudFoundryWebEndpointDiscoverer(ApplicationContext applicationContext,

@Override
protected boolean isExtensionTypeExposed(Class<?> extensionBeanType) {
if (isHealthEndpointExtension(extensionBeanType) && !isCloudFoundryHealthEndpointExtension(extensionBeanType)) {
// Filter regular health endpoint extensions so a CF version can replace them
return false;
}
return true;
// Filter regular health endpoint extensions so a CF version can replace them
return !isHealthEndpointExtension(extensionBeanType)
|| isCloudFoundryHealthEndpointExtension(extensionBeanType);
}

private boolean isHealthEndpointExtension(Class<?> extensionBeanType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public enum InfoContributorFallback {
/**
* Do not fall back, thereby disabling the info contributor.
*/
DISABLE;
DISABLE

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static MeterValue valueOf(String value) {
if (duration != null) {
return new MeterValue(duration);
}
return new MeterValue(Double.valueOf(value));
return new MeterValue(Double.parseDouble(value));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public enum HistogramType {
/**
* Delta histogram.
*/
DELTA;
DELTA

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ protected boolean ignoreApplicationContext(ApplicationContext applicationContext
return true;
}
String managementContextId = applicationContext.getParent().getId() + ":management";
if (!managementContextId.equals(applicationContext.getId())) {
return true;
}
return !managementContextId.equals(applicationContext.getId());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ enum PropagationType {
* <a href="https://github.com/openzipkin/b3-propagation#multiple-headers">B3
* multiple headers</a> propagation.
*/
B3_MULTI;
B3_MULTI

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public boolean isMandatory() {
if (!ObjectUtils.isEmpty(this.parameter.getAnnotationsByType(Nullable.class))) {
return false;
}
return (jsr305Present) ? new Jsr305().isMandatory(this.parameter) : true;
return !jsr305Present || new Jsr305().isMandatory(this.parameter);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ public enum Compression {
/**
* No compression.
*/
NONE;
NONE

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public enum ConstructorDetectorStrategy {
* Refuse to decide implicit mode and instead throw an InvalidDefinitionException
* for ambiguous cases.
*/
EXPLICIT_ONLY;
EXPLICIT_ONLY

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ClassLoaderFile(Kind kind, byte[] contents) {
*/
public ClassLoaderFile(Kind kind, long lastModified, byte[] contents) {
Assert.notNull(kind, "Kind must not be null");
Assert.isTrue((kind != Kind.DELETED) ? contents != null : contents == null,
Assert.isTrue((kind != Kind.DELETED) == (contents != null),
() -> "Contents must " + ((kind != Kind.DELETED) ? "not " : "") + "be null");
this.kind = kind;
this.lastModified = lastModified;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ContextCustomizer createContextCustomizer(Class<?> testClass,
}
OverrideAutoConfiguration overrideAutoConfiguration = TestContextAnnotationUtils.findMergedAnnotation(testClass,
OverrideAutoConfiguration.class);
boolean enabled = (overrideAutoConfiguration != null) ? overrideAutoConfiguration.enabled() : true;
boolean enabled = overrideAutoConfiguration == null || overrideAutoConfiguration.enabled();
return !enabled ? new DisableAutoConfigurationContextCustomizer() : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || obj.getClass() != getClass()) {
return false;
}
return true;
return obj != null && obj.getClass() == getClass();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ enum UseMainMethod {
* that class does not have a main method, a test-specific
* {@link SpringApplication} will be used.
*/
WHEN_AVAILABLE;
WHEN_AVAILABLE

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ private boolean isStandardBeanOrSingletonFactoryBean(ConfigurableListableBeanFac
String factoryBeanName = BeanFactory.FACTORY_BEAN_PREFIX + name;
if (beanFactory.containsBean(factoryBeanName)) {
FactoryBean<?> factoryBean = (FactoryBean<?>) beanFactory.getBean(factoryBeanName);
if (!factoryBean.isSingleton()) {
return false;
}
return factoryBean.isSingleton();
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private SockaddrUn(byte sunFamily, byte[] path) {

@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "sunLen", "sunFamily", "sunPath" });
return Arrays.asList("sunLen", "sunFamily", "sunPath");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private SockaddrUn(byte sunFamily, byte[] path) {

@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "sunFamily", "sunPath" });
return Arrays.asList("sunFamily", "sunPath");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ public String getUsageHelp() {
}

private boolean isHelpShown(Command command) {
if (command instanceof HelpCommand || command instanceof HintCommand) {
return false;
}
return true;
return !(command instanceof HelpCommand) && !(command instanceof HintCommand);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public JSONArray() {
public JSONArray(Collection copyFrom) {
this();
if (copyFrom != null) {
for (Iterator it = copyFrom.iterator(); it.hasNext();) {
put(JSONObject.wrap(it.next()));
for (Object o : copyFrom) {
put(JSONObject.wrap(o));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,16 @@ public JSONTokener(String in) {
*/
public Object nextValue() throws JSONException {
int c = nextCleanInternal();
switch (c) {
case -1:
throw syntaxError("End of input");

case '{':
return readObject();

case '[':
return readArray();

case '\'', '"':
return nextString((char) c);

default:
return switch (c) {
case -1 -> throw syntaxError("End of input");
case '{' -> readObject();
case '[' -> readArray();
case '\'', '"' -> nextString((char) c);
default -> {
this.pos--;
return readLiteral();
}
yield readLiteral();
}
};
}

private int nextCleanInternal() throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ public boolean matches(ConfigurationMetadata value) {
if (this.deprecation == null && itemMetadata.getDeprecation() != null) {
return false;
}
if (this.deprecation != null && !this.deprecation.equals(itemMetadata.getDeprecation())) {
return false;
}
return true;
return this.deprecation == null || this.deprecation.equals(itemMetadata.getDeprecation());
}

public MetadataItemCondition ofType(Class<?> dataType) {
Expand Down Expand Up @@ -348,10 +345,7 @@ public boolean matches(ItemHint value) {
if (this.value != null && !this.value.equals(valueHint.getValue())) {
return false;
}
if (this.description != null && !this.description.equals(valueHint.getDescription())) {
return false;
}
return true;
return this.description == null || this.description.equals(valueHint.getDescription());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void configureFilePermissions(CopySpec copySpec, int mode) {
if (GradleVersion.current().compareTo(GradleVersion.version("8.3")) >= 0) {
try {
Method filePermissions = copySpec.getClass().getMethod("filePermissions", Action.class);
filePermissions.invoke(copySpec, new Action<Object>() {
filePermissions.invoke(copySpec, new Action<>() {

@Override
public void execute(Object filePermissions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void runExtractsLayers() {
private void timeAttributes(File file) {
try {
BasicFileAttributes basicAttributes = Files
.getFileAttributeView(file.toPath(), BasicFileAttributeView.class, new LinkOption[0])
.getFileAttributeView(file.toPath(), BasicFileAttributeView.class)
.readAttributes();
assertThat(basicAttributes.lastModifiedTime().to(TimeUnit.SECONDS))
.isEqualTo(LAST_MODIFIED_TIME.to(TimeUnit.SECONDS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void nativeImageArgFileWithExcludesIsWritten() throws Exception {
expected.add("\\Q" + libraryTwo.getName() + "\\E");
expected.add("^/META-INF/native-image/.*");
assertThat(getPackagedEntryContent("META-INF/native-image/argfile"))
.isEqualTo(expected.stream().collect(Collectors.joining("\n")) + "\n");
.isEqualTo(String.join("\n", expected) + "\n");
}

private File createLibraryJar() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public InputStream getInputStream() throws IOException {

@Override
public boolean getAllowUserInteraction() {
return (this.jarFileConnection != null) ? this.jarFileConnection.getAllowUserInteraction() : false;
return this.jarFileConnection != null && this.jarFileConnection.getAllowUserInteraction();
}

@Override
Expand All @@ -219,7 +219,7 @@ public void setAllowUserInteraction(boolean allowuserinteraction) {

@Override
public boolean getUseCaches() {
return (this.jarFileConnection != null) ? this.jarFileConnection.getUseCaches() : true;
return this.jarFileConnection == null || this.jarFileConnection.getUseCaches();
}

@Override
Expand All @@ -231,7 +231,7 @@ public void setUseCaches(boolean usecaches) {

@Override
public boolean getDefaultUseCaches() {
return (this.jarFileConnection != null) ? this.jarFileConnection.getDefaultUseCaches() : true;
return this.jarFileConnection == null || this.jarFileConnection.getDefaultUseCaches();
}

@Override
Expand Down
Loading