Skip to content

Commit aa81300

Browse files
committed
refactor(ImageFileValidator): check for log level before log with a method that allocates memory.
1 parent f616144 commit aa81300

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main/java/ru/mystamps/web/support/beanvalidation/ImageFileValidator.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,19 @@ public boolean isValid(MultipartFile file, ConstraintValidatorContext ctx) {
139139
return true;
140140
}
141141

142-
LOG.debug(
143-
"Looks like file isn't a PNG image. First bytes: {} {}",
144-
formatBytes(firstPart),
145-
formatBytes(secondPart)
146-
);
142+
if (LOG.isDebugEnabled()) {
143+
LOG.debug(
144+
"Looks like file isn't a PNG image. First bytes: {} {}",
145+
formatBytes(firstPart),
146+
formatBytes(secondPart)
147+
);
148+
}
147149
return false;
148150
}
149151

150-
LOG.debug("Looks like file isn't an image. First bytes: {}", formatBytes(firstPart));
152+
if (LOG.isDebugEnabled()) {
153+
LOG.debug("Looks like file isn't an image. First bytes: {}", formatBytes(firstPart));
154+
}
151155
return false;
152156

153157
} catch (IOException e) {

0 commit comments

Comments
 (0)