You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refactor duplicate JRE implementations into shared BaseJRE struct #1264
Currently the Go buildpack has 6 nearly identical JRE implementations (~1300 lines total): OpenJDK, SapMachine, Zulu, IBM, Oracle, GraalVM. Each has its own copy of Supply(), Finalize(), MemoryCalculatorCommand() etc. with only names/strings differing.
In the Ruby buildpack, this was solved cleanly via inheritance — e.g. ZuluJRE < OpenJDKLike was 3 lines.
Proposed fix
Introduce a shared BaseJRE struct with Go embedding:
typeBaseJREstruct {
ctx*common.ContextjreNamestringenvVarNamestringmemoryCalc*MemoryCalculator...
}
// Supply(), Finalize(), MemoryCalculatorCommand() implemented once on BaseJREtypeZuluJREstruct { BaseJRE }
typeSapMachineJREstruct { BaseJRE }
// etc.
This would reduce ~1300 lines to ~200 lines of shared logic + ~5 lines per vendor.
Context
Discovered while fixing #1257 — the LoadConfig() bug (reading only JBP_CONFIG_OPEN_JDK_JRE for all JREs) was a direct consequence of the duplicated structure. A minimal fix was applied to pass jreName to NewMemoryCalculator. The base struct refactor is the structural follow-up.
After analyzing the refactor in detail, the complexity tradeoff is worth discussing:
What the refactor saves: 6 standard JRE files × ~220 lines = ~1320 lines of near-identical code, reduced to a base_jre.go (~150 lines) + 6 thin constructors (~10 lines each) = ~210 lines. Zing stays separate as it is genuinely different. More importantly, any bug fix or improvement to Supply()/Finalize() currently needs to be applied in all 6 files — and it is easy to miss one.
What it costs: A BaseJRE struct with config/function-field hooks introduces indirection — instead of reading ibm.go top-to-bottom, you jump between the constructor and base_jre.go to follow the flow. Go has no virtual dispatch, so method-override approaches have a 'forgot to call base' footgun; the safer alternative is injecting variation points as function fields, which adds its own complexity.
The variation is already there: Zing has no memory calculator or jvmkill. IBM needs extra JVM opts. GraalVM has a different error message. Oracle and OpenJDK share the same findJavaHome prefix. More special cases will likely follow.
Conclusion: The files are self-contained and easy to read as-is, but the duplication is a real maintenance risk. The refactor pays off most when bugs need to be fixed consistently across all JREs. If the JRE set is stable and rarely changes, the added indirection may not be worth it.
Suggest closing this issue if there is no real benefit.
Activity
fix: LoadConfig reads correct JBP_CONFIG_*_JRE per vendor
stokpop commentedon May 20, 2026
After analyzing the refactor in detail, the complexity tradeoff is worth discussing:
What the refactor saves: 6 standard JRE files × ~220 lines = ~1320 lines of near-identical code, reduced to a
base_jre.go(~150 lines) + 6 thin constructors (~10 lines each) = ~210 lines. Zing stays separate as it is genuinely different. More importantly, any bug fix or improvement toSupply()/Finalize()currently needs to be applied in all 6 files — and it is easy to miss one.What it costs: A
BaseJREstruct with config/function-field hooks introduces indirection — instead of readingibm.gotop-to-bottom, you jump between the constructor andbase_jre.goto follow the flow. Go has no virtual dispatch, so method-override approaches have a 'forgot to call base' footgun; the safer alternative is injecting variation points as function fields, which adds its own complexity.The variation is already there: Zing has no memory calculator or jvmkill. IBM needs extra JVM opts. GraalVM has a different error message. Oracle and OpenJDK share the same
findJavaHomeprefix. More special cases will likely follow.Conclusion: The files are self-contained and easy to read as-is, but the duplication is a real maintenance risk. The refactor pays off most when bugs need to be fixed consistently across all JREs. If the JRE set is stable and rarely changes, the added indirection may not be worth it.
Suggest closing this issue if there is no real benefit.
ramonskie commentedon May 20, 2026
i am always for making things more readable and dedepluication.
so if anyone is interested in picking this up. i will review it
stokpop commentedon May 20, 2026
@ramonskie I created a PR for this #1288 : if you can review it, thanks
refactor: extract BaseJRE to eliminate duplication across standard JR…