Avoid String allocations with Assert.isTrue()

This commit is contained in:
Sam Brannen 2022-11-05 14:51:36 +01:00
parent 82823517fa
commit ac5eb9bfd3
6 changed files with 9 additions and 10 deletions

View File

@ -86,7 +86,7 @@ public class FileSystemGeneratedFiles implements GeneratedFiles {
Assert.notNull(content, "'content' must not be null");
Path root = this.roots.apply(kind).toAbsolutePath().normalize();
Path relativePath = root.resolve(path).toAbsolutePath().normalize();
Assert.isTrue(relativePath.startsWith(root), () -> "'path' must be relative");
Assert.isTrue(relativePath.startsWith(root), "'path' must be relative");
try {
try (InputStream inputStream = content.getInputStream()) {
Files.createDirectories(relativePath.getParent());

View File

@ -161,8 +161,7 @@ public interface GeneratedFiles {
private static String getClassNamePath(String className) {
Assert.hasLength(className, "'className' must not be empty");
Assert.isTrue(isJavaIdentifier(className),
"'className' must be a valid identifier");
Assert.isTrue(isJavaIdentifier(className), "'className' must be a valid identifier");
return ClassUtils.convertClassNameToResourcePath(className) + ".java";
}

View File

@ -241,12 +241,12 @@ public final class RSocketRequestValues {
private final List<MimeType> mimeTypes = new ArrayList<>();
public void addMetadata(Object metadata) {
Assert.isTrue(this.metadata.size() == this.mimeTypes.size(), "Invalid state: " + this);
Assert.isTrue(this.metadata.size() == this.mimeTypes.size(), () -> "Invalid state: " + this);
this.metadata.add(metadata);
}
public void addMimeType(MimeType mimeType) {
Assert.isTrue(this.metadata.size() == (this.mimeTypes.size() + 1), "Invalid state: " + this);
Assert.isTrue(this.metadata.size() == (this.mimeTypes.size() + 1), () -> "Invalid state: " + this);
this.mimeTypes.add(mimeType);
}

View File

@ -52,8 +52,8 @@ class InjectionCodeGenerator {
InjectionCodeGenerator(ClassName targetClassName, RuntimeHints hints) {
Assert.notNull(hints, "TargetClassName must not be null");
Assert.notNull(hints, "Hints must not be null");
Assert.notNull(hints, "ClassName must not be null");
Assert.notNull(hints, "RuntimeHints must not be null");
this.targetClassName = targetClassName;
this.hints = hints;
}
@ -97,7 +97,7 @@ class InjectionCodeGenerator {
CodeBlock resourceToInject) {
Assert.isTrue(method.getParameterCount() == 1,
"Method '" + method.getName() + "' must declare a single parameter");
() -> "Method '" + method.getName() + "' must declare a single parameter");
CodeBlock.Builder code = CodeBlock.builder();
AccessControl accessControl = AccessControl.forMember(method);
if (!accessControl.isAccessibleFrom(this.targetClassName)) {

View File

@ -534,7 +534,7 @@ public final class ContentDisposition {
* @see <a href="https://tools.ietf.org/html/rfc2047">RFC 2047</a>
*/
private static String decodeQuotedPrintableFilename(String filename, Charset charset) {
Assert.notNull(filename, "'input' String` should not be null");
Assert.notNull(filename, "'input' String should not be null");
Assert.notNull(charset, "'charset' should not be null");
byte[] value = filename.getBytes(US_ASCII);

View File

@ -186,7 +186,7 @@ public abstract class AbstractNamedValueArgumentResolver implements HttpServiceA
}
if (value == null) {
Assert.isTrue(!required, "Missing " + valueLabel + " value '" + name + "'");
Assert.isTrue(!required, () -> "Missing " + valueLabel + " value '" + name + "'");
return;
}