Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/java/jres/jre.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ func normalizeVersionPattern(version string) string {
if strings.Contains(version, "*") {
return version
}
// Exact patch version (e.g. "17.0.13") — already fully specified, don't append ".*"
// which would produce an unmatchable pattern like "17.0.13.*".
exactVersionRegex := regexp.MustCompile(`^\d+\.\d+\.\d+$`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Although this code is probably not on a hot path, you can also hoist regexes so its no compiled for each call, e.g.

var threePartVersionPattern = regexp.MustCompile(`^\d+\.\d+\.\d+$`)

func isValidVersion(version string) bool {
	return threePartVersionPattern.MatchString(version)
}

if exactVersionRegex.MatchString(version) {
return version
}
return version + ".*"
}

Expand Down
8 changes: 8 additions & 0 deletions src/java/jres/jre_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ dependencies:
Expect(dep.Name).To(Equal("openjdk"))
Expect(dep.Version).To(Equal("17.0.13"))
})

It("resolves exact patch version", func() {
os.Setenv("BP_JAVA_VERSION", "17.0.13")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The basic fix probably works as far as I can tell, but the actual versions of JRE are like: X.Y.Z+W format (17.0.19+11). Consider adding a test where BP_JAVA_VERSION resolves against a manifest entry 17.0.19+11.

I also thought we use "JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: "25.0.3" } }'", I assume the fix also works for those cases, but maybe also add test case to be sure.

dep, err := jres.GetJREVersion(ctx, "openjdk")
Expect(err).NotTo(HaveOccurred())
Expect(dep.Name).To(Equal("openjdk"))
Expect(dep.Version).To(Equal("17.0.13"))
})
})

Context("without BP_JAVA_VERSION", func() {
Expand Down