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

Make value of SonarProperties#property nullable #247

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

Conversation

Vampire
Copy link
Contributor

@Vampire Vampire commented Sep 10, 2024

I'm porting a Groovy DSL build to Kotlin DSL.

Before I did things like

property('foo', [...] ?: null)

to override foo and either set it to some value or unset it otherwise.

In Kotlin DSL you cannot do

property("foo", listOf(...).takeIf { it.isNotEmpty() })

currently due to the @ParametersAreNonnullByDefault in the package-info.java and Kotlin respecting that, so having the value parameter non-nullable.
Work-around is to use

properties["foo"] = listOf(...).takeIf { it.isNotEmpty() }

or

listOf(...).also { if (it.isNotEmpty()) property("foo", it) else properties.remove("foo") }

This PR makes the value parameter nullable, so you can also use the first Kotlin snippet above.

@dorian-burihabwa-sonarsource
Copy link
Contributor

hey @Vampire, thank you for the suggestion. Do you have any tests that effectively show that a nullable value actually removes the property from the collection?

@Vampire
Copy link
Contributor Author

Vampire commented Oct 15, 2024

I don't really get your comment, sorry.

This is not a suggestion, but a definite bug report.

And it of course does not remove the property from the collection, why should it? It sets is value in the collection to null.

@dorian-burihabwa-sonarsource
Copy link
Contributor

I don't really get your comment, sorry.

This is not a suggestion, but a definite bug report.

My bad, I did not understand what you were trying to achieve here.

And it of course does not remove the property from the collection, why should it? It sets is value in the collection to null.

Could you share, here or in the community forums, an example of a build configuration that triggers the bug?

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.

3 participants