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

Replaced Arguements With Empty Array #1614

Merged
merged 6 commits into from
Jan 14, 2024

Conversation

shivajee98
Copy link
Contributor

No description provided.

@shivajee98 shivajee98 requested a review from a team as a code owner January 14, 2024 05:22
@krisstern
Copy link
Member

Hi @shivajee98,
What is the motivation behind this PR and does it resolve a particular issue in the issue tracker?

@shivajee98
Copy link
Contributor Author

Using new String[0] is considered more idiomatic in modern java development
as the array is then dynamically resized as needed.
My motivation was to follow a more modern and concise coding style.

@krisstern
Copy link
Member

I am guessing you mean something like the one reference here https://stackoverflow.com/a/65902425/9959070:

There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]). In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation. This inspection allows to follow the uniform style: either using an empty array (which is recommended in modern Java) or using a pre-sized array (which might be faster in older Java versions or non-HotSpot based JVMs).

That makes sense, but it would be great for you to provide some context for the PR instead of having an empty description. We do not encourge that practice in open-source software development, as we would have no idea why the contributor is proposing the change.

Copy link
Member

@krisstern krisstern left a comment

Choose a reason for hiding this comment

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

LGTM

@krisstern krisstern merged commit 959ab07 into jenkinsci:master Jan 14, 2024
17 checks passed
@krisstern krisstern added the enhancement For changelog: Minor enhancement. Use 'major-rfe' for changes to be highlighted label Jan 14, 2024
@krisstern
Copy link
Member

Thanks!

@shivajee98
Copy link
Contributor Author

I am guessing you mean something like the one reference here https://stackoverflow.com/a/65902425/9959070:

There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]). In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty array version the same and sometimes even better, compared to the pre-sized version. Also passing pre-sized array is dangerous for a concurrent or synchronized collection as a data race is possible between the size and toArray call which may result in extra nulls at the end of the array, if the collection was concurrently shrunk during the operation. This inspection allows to follow the uniform style: either using an empty array (which is recommended in modern Java) or using a pre-sized array (which might be faster in older Java versions or non-HotSpot based JVMs).

That makes sense, but it would be great for you to provide some context for the PR instead of having an empty description. We do not encourge that practice in open-source software development, as we would have no idea why the contributor is proposing the change.

Thank you for your feedback. I appreciate the guidance on providing meaningful context for the PR. I apologize for the oversight in this instance.

Moving forward, I assure you that I will make it a priority to offer detailed descriptions for my contributions. I understand the importance of clear communication in open-source development, and I am committed to providing comprehensive explanations for any changes I propose.
Thank you for your understanding.

@krisstern
Copy link
Member

Hi @shivajee98, I am afraid we may need to revert the changes due to the concern that an empty Array will stay with dimension 0 after initialisation. This goes against what we are trying to achieve as Array is unlike ArrayList and is of a fixed size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement For changelog: Minor enhancement. Use 'major-rfe' for changes to be highlighted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants