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: Stack overflow on multi maps (and other non-trivial generic clas… #4501

Merged
merged 1 commit into from Oct 19, 2022

Conversation

xRodney
Copy link
Contributor

@xRodney xRodney commented Oct 14, 2022

Description

…ses), schema for multimaps is wrong

Logic in sundrio that is responsible for replacing generic type arguments on methods and properties with their concrete instantiations from subclasses contained a bug, in which it looped infinitely if the same type argument name was used at multiple classes in the hierarchy. A common occurence were multimaps.

A very similar code was also present in crd-generator, also suffering from the same bug.

Sundrio has been updated to account for this situation, and updated utilities from sundrio have been introduced to crd-generator, which replace the previous implementation of the same algorithm.

A test has been added to validate that multimaps (like class MultiMap<K,V> implements Map<K,List<V>>) are generated correctly.

Fixes #4357
Fixes #4487
Supersedes closes #4504

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@xRodney
Copy link
Contributor Author

xRodney commented Oct 14, 2022

It seems that sundrio 0.93.1 is not yet fully released. I will make it Ready for review once it is.

@xRodney xRodney force-pushed the bugfix/multi-maps4 branch 2 times, most recently from f8acda3 to bf5df02 Compare October 18, 2022 06:33
@xRodney
Copy link
Contributor Author

xRodney commented Oct 18, 2022

Sundrio has been released (thanks @iocanel), this is now ready for review.
(That one failing E2E test is a false alarm, in my opinion)

@xRodney xRodney marked this pull request as ready for review October 18, 2022 07:36
Copy link
Member

@andreaTP andreaTP left a comment

Choose a reason for hiding this comment

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

Overall this looks good, thanks a lot @xRodney !

I added one question and if you can find more tests to cover possible edge cases it would be nice (e.g. different number of generic type parameters etc. etc.).

@xRodney
Copy link
Contributor Author

xRodney commented Oct 19, 2022

I have added more tests to crd-generator-api. I also copied most of the cases to crd-generator-test, because I was worried about possible differences between Sundrio Reflection and APT contexts. But all seems to be good.

Btw, there is already quite an extensive test suite in sundrio here and here

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class ContainingMapsCRDTest {
Copy link
Member

Choose a reason for hiding this comment

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

Most of these tests could be refactored to use single assertions with AssertJ, but it's not big deal

Copy link
Member

Choose a reason for hiding this comment

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

OK, this is probably a port of CRDGeneratorTest. That one needs some refactoring too 😅

Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

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

LGTM (codewise)

…es), schema for multimaps is wrong

Logic in sundrio that is responsible for replacing generic type arguments on methods and properties with their concrete instantiations from subclasses contained a bug, in which it looped infinitely if the same type argument name was used at multiple classes in the hierarchy. A common occurence were multimaps.

A very similar code was also present in crd-generator, also suffering from the same bug.

Sundrio has been updated to account for this situation, and updated utilities from sundrio have been introduced to crd-generator, which replace the previous implementation of the same algorithm.

A test has been added to validate that multimaps (like `class MultiMap<K,V> implements Map<K,List<V>>`) are generated correctly.

Fixes fabric8io#4357
Fixes fabric8io#4487
@manusa manusa added this to the 6.2.0 milestone Oct 19, 2022
@sonarcloud
Copy link

sonarcloud bot commented Oct 19, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@andreaTP andreaTP left a comment

Choose a reason for hiding this comment

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

Lgtm! Thanks a lot for this fix @xRodney ! Much appreciated!

@manusa manusa merged commit dad9c22 into fabric8io:master Oct 19, 2022
@xRodney xRodney deleted the bugfix/multi-maps4 branch October 29, 2022 20:26
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.

Schema for multimaps is wrong Stack overflow on multi maps (and other non-trivial generic classes)
3 participants