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

Fix some ErrorProne issues in :model-core #28892

Merged
merged 12 commits into from May 8, 2024
Merged

Conversation

mlopatkin
Copy link
Member

Reviewing cheatsheet

Before merging the PR, comments starting with

  • ❌ ❓must be fixed
  • 🤔 💅 should be fixed
  • 💭 may be fixed
  • 🎉 celebrate happy things

@mlopatkin mlopatkin added the a:chore Minor issue without significant impact label Apr 19, 2024
@mlopatkin mlopatkin self-assigned this Apr 19, 2024
@mlopatkin mlopatkin added this to the 8.9 RC1 milestone Apr 19, 2024
@mlopatkin mlopatkin marked this pull request as ready for review April 19, 2024 21:54
@mlopatkin mlopatkin requested a review from a team as a code owner April 19, 2024 21:54
@mlopatkin mlopatkin requested review from bamboo and abstratt and removed request for a team April 19, 2024 21:54
@@ -144,16 +144,16 @@ public int getLinkCount(Predicate<? super MutableModelNode> predicate) {
@Override
public Set<String> getLinkNames(Predicate<? super MutableModelNode> predicate) {
if (links == null) {
return Collections.emptySet();
return ImmutableSet.of();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 this has a benefit of avoiding extra copy when the result is used as an argument to ImmutableSet.copyOf.

@@ -535,17 +536,17 @@ private BindingPredicate mapSubject(ModelReference<?> subjectReference, ModelAct

private List<BindingPredicate> mapInputs(List<? extends ModelReference<?>> inputs) {
if (inputs.isEmpty()) {
return Collections.emptyList();
return ImmutableList.of();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 this has a benefit of avoiding extra copy when the result is used as an argument to ImmutableList.copyOf.

@@ -252,7 +252,7 @@ public Object[] toArray() {
}

@Override
public <T> T[] toArray(T[] a) {
public <E> E[] toArray(E[] a) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 to my surprise, you can pass any array to the Collection.toArray method, even of a completely unrelated type.

@@ -336,10 +339,11 @@ public HasMultipleValues<T> convention(Provider<? extends Iterable<? extends T>>

@Override
protected String describeContents() {
return String.format("%s(%s, %s)", collectionType.getSimpleName().toLowerCase(), elementType, describeValue());
String typeDisplayName = TextUtil.toLowerCaseLocaleSafe(collectionType.getSimpleName());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 unlike MapPropery, here we can only have List or Set, so using the English locale is fine.

@@ -83,7 +83,8 @@ private MappedProperty map(String propertyName, MappedPropertyImpl mapping) {
throw new IllegalStateException(String.format("Could not access property %s.%s", sourceType.getSimpleName(), propertyName), e);
}
if (!mapConventionOn(target, mapping)) {
throw new IllegalStateException(String.format("Unexpected convention-supporting type used in property %s.%s", sourceType.getSimpleName(), propertyName, getter.getReturnType().getName()));
throw new IllegalStateException(String.format(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 A real bug caught!

@@ -469,6 +469,8 @@ protected DynamicInvokeResult setOpaqueProperty(MetaClass metaClass, String name
return DynamicInvokeResult.notFound();
}

@SuppressWarnings("MixedMutabilityReturnType")
// This might be too invasive to fix properly because it is in the dynamic code.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 It looks like making all paths mutable is going to add overhead of allocating empty hashmaps, and making all paths immutable can actually break things.

@@ -54,7 +54,7 @@ public class DefaultConvention implements org.gradle.api.plugins.Convention, Ext
private final InstanceGenerator instanceGenerator;

private Map<String, Object> plugins;
private Map<Object, BeanDynamicObject> dynamicObjects;
private IdentityHashMap<Object, BeanDynamicObject> dynamicObjects;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 ErrorProne insists that IndentityHashMap shouldn't be mixed with Map because of a different contract with regard to hashCode/equals.

Fixing it doesn't look too ugly anyway.

@mlopatkin mlopatkin added this pull request to the merge queue May 4, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 4, 2024
@gradle gradle deleted a comment from mlopatkin May 4, 2024
@mlopatkin
Copy link
Member Author

@bot-gradle test PT

@bot-gradle
Copy link
Collaborator

I've triggered the following builds for you. Click here to see all build failures.

@gitstream-cm gitstream-cm bot removed the a:chore Minor issue without significant impact label May 6, 2024
@blindpirate blindpirate added this pull request to the merge queue May 7, 2024
@blindpirate blindpirate removed this pull request from the merge queue due to a manual request May 7, 2024
Copy link
Member

@bamboo bamboo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

"[k1: v1] + [k2: v2]" | { property().tap { put("k1", "v1"); put("k2", "v2") } } || "Map(string->String, {k1=v1} + {k2=v2})"
"provider {k: v}" | { property().value(Providers.of([k: "v"])) } || "Map(string->String, fixed(class ${LinkedHashMap.name}, {k=v}))"
"[k: provider {v}]" | { property().tap { put("k", Providers.of("v")) } } || "Map(string->String, entry{k=fixed(class ${String.name}, v)})"
"default" | { property() } || "Map(String->String, {})"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bamboo
Copy link
Member

bamboo commented May 8, 2024

@bot-gradle merge

@gradle gradle deleted a comment from mlopatkin May 8, 2024
@bot-gradle bot-gradle added this pull request to the merge queue May 8, 2024
Merged via the queue into master with commit bc54b5e May 8, 2024
32 checks passed
@bot-gradle bot-gradle deleted the ml/errorprone-model-core branch May 8, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants