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

style: Fix some more sonar issues with service #1134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dwalluck
Copy link
Contributor

@dwalluck dwalluck commented Feb 7, 2025

No description provided.

Comment on lines +631 to +636
.setDescription(
manifestBom.getMetadata()
.getComponent()
.getDescription()
.replace(buildManifest.getRootPurl(), rebuiltPurl));
Copy link
Contributor Author

@dwalluck dwalluck Feb 7, 2025

Choose a reason for hiding this comment

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

@vibe13 I think this should fix the issue where description wasn't actually being changed. But, there appears to be no test for this as the tests were unaffected either way.

@@ -211,7 +211,7 @@ protected boolean isFinished(TaskRun taskRun) {
protected Boolean isSuccessful(TaskRun taskRun) {
if (!isFinished(taskRun)) {
log.trace("TaskRun '{}' still in progress", taskRun.getMetadata().getName());
return null;
return null; // FIXME: This is not really binary, but trinary state
Copy link
Contributor Author

@dwalluck dwalluck Feb 7, 2025

Choose a reason for hiding this comment

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

Sonar is complaining about all these comparisons that do not use a primitive type, so I changed the comparisons to avoid the potential of null. Maybe this should use some sort of status enum instead.

@dwalluck dwalluck marked this pull request as draft February 7, 2025 23:07
@@ -108,7 +106,6 @@ public <T> Predicate createPredicate(
}

private String preprocessLikeOperatorArgument(String argument) {
return argument.replaceAll("_", Matcher.quoteReplacement(ESCAPE_CHAR + "_"))
.replaceAll("\\" + WILDCARD_CHAR, "%");
return argument.replace("_", ESCAPE_CHAR + "_").replaceAll("\\" + WILDCARD_CHAR, "%");
Copy link
Contributor Author

@dwalluck dwalluck Feb 8, 2025

Choose a reason for hiding this comment

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

The first one is not a regex. Does the second one need to be a regex? Is it replacing everything including and after a '\' with '%'?.

@dwalluck dwalluck force-pushed the sonar-service branch 7 times, most recently from 2a76d47 to 70ab6b1 Compare February 10, 2025 15:51
Comment on lines +149 to +154
.sorted(
Comparator.comparingInt(String::length)
.reversed() // longest first
.thenComparing(Comparator.naturalOrder()))
.collect(Collectors.toCollection(LinkedHashSet::new));
return Collections.unmodifiableSet(set);
Copy link
Contributor Author

@dwalluck dwalluck Feb 10, 2025

Choose a reason for hiding this comment

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

I fixed this to use LinkedHashSet so that it's actually sorted.

This change also affects the test (that actually test the incorrect ordering).

I added the .thenComparing(Comparator.naturalOrder())) to handle strings of the same length so that we get a predictable ordering when the lengths are identical.

@dwalluck dwalluck force-pushed the sonar-service branch 8 times, most recently from 8a407ae to 5664883 Compare February 11, 2025 17:41
Comment on lines 152 to 182
@Override
public final boolean equals(Object o) {
if (this == o) {
return true;
}

if (o == null) {
return false;
}

Class<?> oEffectiveClass = o instanceof HibernateProxy
? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass()
: o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass()
: this.getClass();

if (thisEffectiveClass != oEffectiveClass) {
return false;
}

RequestEvent requestEvent = (RequestEvent) o;
return Objects.equals(id, requestEvent.id);
}

@Override
public final int hashCode() {
return (this instanceof HibernateProxy)
? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode()
: getClass().hashCode();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

JPA Buddy says to not use @Data and @EqualsAndHashCode with JPA entities.

https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/

@dwalluck dwalluck marked this pull request as ready for review February 11, 2025 17:59
@dwalluck dwalluck force-pushed the sonar-service branch 5 times, most recently from dca1a72 to f72aa88 Compare February 19, 2025 15:37
@goldmann goldmann self-requested a review February 20, 2025 10:44
@@ -147,4 +149,35 @@ public RequestEvent save() {
return this;
}

@Override
public final boolean equals(Object o) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@vibe13 I saw @dwalluck mentioning https://jpa-buddy.com/blog/lombok-and-jpa-what-may-go-wrong/, but can you maybe review this part of the change since you have more experience with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that for database objects with a key (id), it makes sense to rely on the key alone for identity regardless of whether using hibernate. This is what we do with the Koji/Brew objects https://github.com/release-engineering/kojiji/blob/master/src/main/java/com/redhat/red/build/koji/model/xmlrpc/KojiBuildInfo.java#L473-L494.

Copy link
Contributor

@goldmann goldmann left a comment

Choose a reason for hiding this comment

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

I looked at the PR and it looks good, thanks! I just want confirmation from @vibe13 that the equals method implementation is what we would expect it to be. Afterwards we can merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants