Use Supplier variants of Assert
See gh-19864
This commit is contained in:
committed by
Stephane Nicoll
parent
9fbaf7611b
commit
d8e2349e47
@@ -121,7 +121,7 @@ final class ApiVersion {
|
||||
static ApiVersion parse(String value) {
|
||||
Assert.hasText(value, "Value must not be empty");
|
||||
Matcher matcher = PATTERN.matcher(value);
|
||||
Assert.isTrue(matcher.matches(), "Malformed version number '" + value + "'");
|
||||
Assert.isTrue(matcher.matches(), () -> "Malformed version number '" + value + "'");
|
||||
try {
|
||||
int major = Integer.parseInt(matcher.group(1));
|
||||
int minor = Integer.parseInt(matcher.group(2));
|
||||
|
||||
@@ -49,7 +49,7 @@ class BuildOwner implements Owner {
|
||||
|
||||
private long getValue(Map<String, String> env, String name) {
|
||||
String value = env.get(name);
|
||||
Assert.state(StringUtils.hasText(value), "Missing '" + name + "' value from the builder environment");
|
||||
Assert.state(StringUtils.hasText(value), () -> "Missing '" + name + "' value from the builder environment");
|
||||
try {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ class BuilderMetadata extends MappedObject {
|
||||
Assert.notNull(imageConfig, "ImageConfig must not be null");
|
||||
Map<String, String> labels = imageConfig.getLabels();
|
||||
String json = (labels != null) ? labels.get(LABEL_NAME) : null;
|
||||
Assert.notNull(json, "No '" + LABEL_NAME + "' label found in image config");
|
||||
Assert.notNull(json, () -> "No '" + LABEL_NAME + "' label found in image config");
|
||||
return fromJson(json);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class StackId {
|
||||
private static StackId fromImageConfig(ImageConfig imageConfig) {
|
||||
Map<String, String> labels = imageConfig.getLabels();
|
||||
String value = (labels != null) ? labels.get(LABEL_NAME) : null;
|
||||
Assert.state(StringUtils.hasText(value), "Missing '" + LABEL_NAME + "' stack label");
|
||||
Assert.state(StringUtils.hasText(value), () -> "Missing '" + LABEL_NAME + "' stack label");
|
||||
return new StackId(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ public final class ImageReference {
|
||||
* @throws IllegalStateException if the image reference contains a digest
|
||||
*/
|
||||
public ImageReference inTaggedForm() {
|
||||
Assert.state(this.digest == null, "Image reference '" + this + "' cannot contain a digest");
|
||||
Assert.state(this.digest == null, () -> "Image reference '" + this + "' cannot contain a digest");
|
||||
return new ImageReference(this.name, (this.tag != null) ? this.tag : LATEST, this.digest);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public final class ImageReference {
|
||||
*/
|
||||
public static ImageReference forJarFile(File jarFile) {
|
||||
String filename = jarFile.getName();
|
||||
Assert.isTrue(filename.toLowerCase().endsWith(".jar"), "File '" + jarFile + "' is not a JAR");
|
||||
Assert.isTrue(filename.toLowerCase().endsWith(".jar"), () -> "File '" + jarFile + "' is not a JAR");
|
||||
filename = filename.substring(0, filename.length() - 4);
|
||||
int firstDot = filename.indexOf('.');
|
||||
if (firstDot == -1) {
|
||||
|
||||
@@ -85,7 +85,7 @@ public final class LayerId {
|
||||
public static LayerId of(String value) {
|
||||
Assert.hasText(value, "Value must not be empty");
|
||||
int i = value.indexOf(':');
|
||||
Assert.isTrue(i >= 0, "Invalid layer ID '" + value + "'");
|
||||
Assert.isTrue(i >= 0, () -> "Invalid layer ID '" + value + "'");
|
||||
return new LayerId(value, value.substring(0, i), value.substring(i + 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,8 @@ public final class VolumeName {
|
||||
}
|
||||
|
||||
private static String asHexString(byte[] digest, int digestLength) {
|
||||
Assert.isTrue(digestLength <= digest.length, "DigestLength must be less than or equal to " + digest.length);
|
||||
Assert.isTrue(digestLength <= digest.length,
|
||||
() -> "DigestLength must be less than or equal to " + digest.length);
|
||||
byte[] shortDigest = new byte[6];
|
||||
System.arraycopy(digest, 0, shortDigest, 0, shortDigest.length);
|
||||
return String.format("%0" + digestLength + "x", new BigInteger(1, shortDigest));
|
||||
|
||||
@@ -200,7 +200,7 @@ public class MappedObject {
|
||||
if (declaringClass == Object.class) {
|
||||
method.invoke(proxy, args);
|
||||
}
|
||||
Assert.state(args == null || args.length == 0, "Unsupported method " + method);
|
||||
Assert.state(args == null || args.length == 0, () -> "Unsupported method " + method);
|
||||
String name = getName(method.getName());
|
||||
Class<?> type = method.getReturnType();
|
||||
return valueForProperty(name, type);
|
||||
|
||||
@@ -65,7 +65,7 @@ class BsdDomainSocket extends DomainSocket {
|
||||
public byte[] sunPath = new byte[MAX_PATH_LENGTH];
|
||||
|
||||
private SockaddrUn(byte sunFamily, byte[] path) {
|
||||
Assert.isTrue(path.length < MAX_PATH_LENGTH, "Path cannot exceed " + MAX_PATH_LENGTH + " bytes");
|
||||
Assert.isTrue(path.length < MAX_PATH_LENGTH, () -> "Path cannot exceed " + MAX_PATH_LENGTH + " bytes");
|
||||
System.arraycopy(path, 0, this.sunPath, 0, path.length);
|
||||
this.sunPath[path.length] = 0;
|
||||
this.sunLen = (byte) (fieldOffset("sunPath") + path.length);
|
||||
|
||||
@@ -63,7 +63,7 @@ class LinuxDomainSocket extends DomainSocket {
|
||||
public byte[] sunPath = new byte[MAX_PATH_LENGTH];
|
||||
|
||||
private SockaddrUn(byte sunFamily, byte[] path) {
|
||||
Assert.isTrue(path.length < MAX_PATH_LENGTH, "Path cannot exceed " + MAX_PATH_LENGTH + " bytes");
|
||||
Assert.isTrue(path.length < MAX_PATH_LENGTH, () -> "Path cannot exceed " + MAX_PATH_LENGTH + " bytes");
|
||||
System.arraycopy(path, 0, this.sunPath, 0, path.length);
|
||||
this.sunPath[path.length] = 0;
|
||||
this.sunFamily = sunFamily;
|
||||
|
||||
Reference in New Issue
Block a user