mirror of https://github.com/sbt/sbt.git
[2.x] fix: Add null check for resource URL in ResourceLoader.getPropertiesFor (#8641)
**Problem** getPropertiesFor method calls getResource().openStream() without checking if getResource returns null. When a resource doesn't exist, this causes a NullPointerException with no context about which resource was missing. **Solution** Added null check before calling openStream() and throw a descriptive FileNotFoundException with the resource name if the resource is not found. This prevents NullPointerException and provides better error messages. Generated-by: Auto
This commit is contained in:
parent
cc0915fed9
commit
aa4ac5b981
|
|
@ -14,7 +14,11 @@ import java.util.Properties
|
|||
private[inc] object ResourceLoader {
|
||||
def getPropertiesFor(resource: String): Properties = {
|
||||
val properties = new Properties
|
||||
val propertiesStream = getClass.getResource(resource).openStream
|
||||
val resourceUrl = getClass.getResource(resource)
|
||||
if (resourceUrl eq null) {
|
||||
throw new java.io.FileNotFoundException(s"Resource not found: $resource")
|
||||
}
|
||||
val propertiesStream = resourceUrl.openStream
|
||||
try {
|
||||
properties.load(propertiesStream)
|
||||
} finally propertiesStream.close()
|
||||
|
|
|
|||
Loading…
Reference in New Issue