Skip to content

Commit 23de76d

Browse files
kurellajuniormp911de
authored andcommitted
Avoid NullPointerException´ and IllegalArgumentException for control flow in Sort`.
Checking for null explicitly is cheap and prevents two unnecessary Exception objects creations. Closes #3081
1 parent 289e4d1 commit 23de76d

File tree

1 file changed

+6
-1
lines changed
  • src/main/java/org/springframework/data/domain

1 file changed

+6
-1
lines changed

src/main/java/org/springframework/data/domain/Sort.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* @author Thomas Darimont
4242
* @author Mark Paluch
4343
* @author Johannes Englmeier
44+
* @author Jan Kurella
4445
*/
4546
public class Sort implements Streamable<org.springframework.data.domain.Sort.Order>, Serializable {
4647

@@ -341,14 +342,18 @@ public static Direction fromString(String value) {
341342
}
342343

343344
/**
344-
* Returns the {@link Direction} enum for the given {@link String} or null if it cannot be parsed into an enum
345+
* Returns the {@link Direction} enum for the given {@link String} or empty if it cannot be parsed into an enum
345346
* value.
346347
*
347348
* @param value
348349
* @return
349350
*/
350351
public static Optional<Direction> fromOptionalString(String value) {
351352

353+
if (value == null) {
354+
return Optional.empty();
355+
}
356+
352357
try {
353358
return Optional.of(fromString(value));
354359
} catch (IllegalArgumentException e) {

0 commit comments

Comments
 (0)