Skip to content

Commit ee246ea

Browse files
Polish interpolation and javadocs
1 parent 0850fce commit ee246ea

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/main/java/io/github/problem4j/core/DefaultProblemContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ final class DefaultProblemContext implements ProblemContext, Serializable {
3737
return context.get(key);
3838
}
3939

40+
@Override
41+
public boolean containsKey(String key) {
42+
return context.containsKey(key);
43+
}
44+
4045
@Override
4146
public ProblemContext put(String key, @Nullable String value) {
4247
if (value == null) {

src/main/java/io/github/problem4j/core/DefaultProblemMapper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public DefaultProblemMapper() {}
9494
* annotation. Such builder can be further extended or executed to create {@link Problem}
9595
* response.
9696
*
97+
* <p>This method is {@code final} and always delegates to {@link #toProblemBuilder(Throwable,
98+
* ProblemContext)} with a {@code null} context. Subclasses should override {@link
99+
* #toProblemBuilder(Throwable, ProblemContext)} to customize mapping behavior.
100+
*
97101
* @param t {@link Throwable} to convert (may be {@code null})
98102
* @return a {@link ProblemBuilder} instance
99103
* @throws ProblemMappingException when something goes wrong while building the Problem
@@ -368,8 +372,8 @@ protected String interpolate(String template, Throwable t, @Nullable ProblemCont
368372
replacement = t.getMessage() == null ? "" : String.valueOf(t.getMessage());
369373
} else if (key.startsWith(CONTEXT_LABEL_PREFIX)) {
370374
String contextKey = key.substring(CONTEXT_LABEL_PREFIX.length());
371-
replacement =
372-
(context == null || !context.containsKey(contextKey)) ? "" : context.get(contextKey);
375+
String contextValue = context != null ? context.get(contextKey) : null;
376+
replacement = contextValue != null ? contextValue : "";
373377
} else {
374378
Object v = resolvePlaceholderSource(t, key);
375379
replacement = (v == null) ? "" : String.valueOf(v);

src/main/java/io/github/problem4j/core/ProblemMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
* exception class is not annotated with {@link ProblemMapping}, and may throw {@link
4343
* ProblemMappingException} if an error occurs during problem creation.
4444
*
45+
* <p>An empty builder is indistinguishable from a builder produced by an annotation with all blank
46+
* fields; callers should use {@link #isMappingCandidate(Throwable)} to determine whether an
47+
* exception is eligible for mapping before calling {@code toProblemBuilder}.
48+
*
4549
* @since 1.3.0
4650
*/
4751
public interface ProblemMapper {

0 commit comments

Comments
 (0)