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

[Jenkins-65548] Fix - Random ordering of generated sources #702

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

code-arnab
Copy link
Contributor

Testing done

Closes this - JIRA Ticket

To fix this issue, I've utilized Arrays.sort() (Alphabetically sorted by ignoring cases). This aims to maintain a consistent order which is necessary for reproducible builds.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@@ -118,6 +119,10 @@ private void report(JPackage pkg, String fileName) {
private void walk(File dir, JPackage pkg, String dirName) throws JClassAlreadyExistsException, IOException {
File[] children = dir.listFiles(File::isDirectory);
if (children != null) {
// Sorting the children to maintain a consistent order
// This is important for reproducible builds
Arrays.sort(children, (a, b) -> a.getName().compareToIgnoreCase(b.getName()));
Copy link
Member

Choose a reason for hiding this comment

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

Generally prefer simple case-sensitive compare unless there is a specific reason to make it case-insensitive. I guess it should not matter here because the only way the current code could result in an unreproducible order is if the directory contained two files differing only in case, like something.jelly + someThing.jelly, in which case the random order from listFiles would be preserved by this sort. But in that situation the repository could not even be checked out on Windows so someone would probably have noticed the mistake long ago anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank You for the tip. Will keep in mind.

@jglick jglick enabled auto-merge (squash) December 19, 2024 15:00
@jglick jglick added the bug label Dec 19, 2024
@jglick jglick merged commit f656765 into jenkinsci:master Dec 19, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants