Class ParameterizedMessage
- All Implemented Interfaces:
Serializable
,Message
,StringBuilderFormattable
Message
accepting argument placeholders in the formatting pattern.
Only "{}" strings are treated as argument placeholders.
Escaped (i.e., "\"
-prefixed) or incomplete argument placeholders will be ignored.
Examples of argument placeholders that will be discarded and rendered intact:
{ } foo\{} {bar {buzz}
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionParameterizedMessage
(String pattern, Object arg) Constructor with a pattern and a single argument.ParameterizedMessage
(String pattern, Object... args) Constructor with a pattern and multiple arguments.ParameterizedMessage
(String pattern, Object[] args, Throwable throwable) Constructs an instance.ParameterizedMessage
(String pattern, Object arg0, Object arg1) Constructor with a pattern and two arguments.ParameterizedMessage
(String pattern, String[] args, Throwable throwable) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
countArgumentPlaceholders
(String pattern) Returns the number of argument placeholders.static String
This method performs a deep toString of the given Object.boolean
static String
Returns the formatted message.void
formatTo
(StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.This method has unclear semantics and inconsistent implementations – its usage is strongly discouraged.Returns the formatted message.Object[]
Gets parameter values, if any.TheThrowable
provided along with the message by one of the following means: explicitly in the constructor as the last message argument that is not referred to by any placeholder in the formatting patternint
hashCode()
static String
identityToString
(Object obj) This method returns the same as if Object.toString() would not have been overridden in obj.toString()
-
Field Details
-
RECURSION_PREFIX
Prefix for recursion.- See Also:
-
RECURSION_SUFFIX
Suffix for recursion.- See Also:
-
ERROR_PREFIX
Prefix for errors.- See Also:
-
ERROR_SEPARATOR
Separator for errors.- See Also:
-
ERROR_MSG_SEPARATOR
Separator for error messages.- See Also:
-
ERROR_SUFFIX
Suffix for errors.- See Also:
-
-
Constructor Details
-
ParameterizedMessage
@InlineMe(replacement="this(pattern, Arrays.stream(args).toArray(Object[]::new), throwable)", imports="java.util.Arrays") @Deprecated public ParameterizedMessage(String pattern, String[] args, Throwable throwable) Deprecated.Since 2.6, useParameterizedMessage(String, Object[], Throwable)
insteadConstructs an instance.The
Throwable
associated with the message (and returned ingetThrowable()
) will be determined as follows:- If a
throwable
argument is provided - If the last argument is a
Throwable
and is not referred to by any placeholder in the pattern
- Parameters:
pattern
- a formatting patternargs
- arguments to be formattedthrowable
- aThrowable
- If a
-
ParameterizedMessage
Constructs an instance.The
Throwable
associated with the message (and returned ingetThrowable()
) will be determined as follows:- If a
throwable
argument is provided - If the last argument is a
Throwable
and is not referred to by any placeholder in the pattern
- Parameters:
pattern
- a formatting patternargs
- arguments to be formattedthrowable
- aThrowable
- If a
-
ParameterizedMessage
Constructor with a pattern and multiple arguments.If the last argument is a
Throwable
and is not referred to by any placeholder in the pattern, it is returned ingetThrowable()
.- Parameters:
pattern
- a formatting patternargs
- arguments to be formatted
-
ParameterizedMessage
Constructor with a pattern and a single argument.If the argument is a
Throwable
and is not referred to by any placeholder in the pattern, it is returned ingetThrowable()
.- Parameters:
pattern
- a formatting patternarg
- an argument
-
ParameterizedMessage
Constructor with a pattern and two arguments.If the last argument is a
Throwable
and is not referred to by any placeholder in the pattern, it is returned ingetThrowable()
and won't be contained in the formatted message.- Parameters:
pattern
- a formatting patternarg0
- the first argumentarg1
- the second argument
-
-
Method Details
-
getFormat
Description copied from interface:Message
This method has unclear semantics and inconsistent implementations – its usage is strongly discouraged. -
getParameters
Description copied from interface:Message
Gets parameter values, if any.- Specified by:
getParameters
in interfaceMessage
- Returns:
- the message arguments
-
getThrowable
TheThrowable
provided along with the message by one of the following means:- explicitly in the constructor
- as the last message argument that is not referred to by any placeholder in the formatting pattern
- Specified by:
getThrowable
in interfaceMessage
- Returns:
- the
Throwable
provided along with the message
-
getFormattedMessage
Returns the formatted message.If possible, the result will be cached for subsequent invocations.
- Specified by:
getFormattedMessage
in interfaceMessage
- Returns:
- the formatted message
-
formatTo
Description copied from interface:StringBuilderFormattable
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.- Specified by:
formatTo
in interfaceStringBuilderFormattable
- Parameters:
buffer
- the StringBuilder to write into
-
format
Returns the formatted message.- Parameters:
pattern
- a message pattern containing argument placeholdersargs
- arguments to be used to replace placeholders
-
equals
-
hashCode
public int hashCode() -
countArgumentPlaceholders
Returns the number of argument placeholders.- Parameters:
pattern
- the message pattern to be analyzed
-
deepToString
This method performs a deep toString of the given Object. Primitive arrays are converted using their respective Arrays.toString methods while special handling is implemented for "container types", i.e. Object[], Map and Collection because those could contain themselves.It should be noted that neither AbstractMap.toString() nor AbstractCollection.toString() implement such a behavior. They only check if the container is directly contained in itself, but not if a contained container contains the original one. Because of that, Arrays.toString(Object[]) isn't safe either. Confusing? Just read the last paragraph again and check the respective toString() implementation.
This means, in effect, that logging would produce a usable output even if an ordinary System.out.println(o) would produce a relatively hard-to-debug StackOverflowError.
- Parameters:
o
- The object.- Returns:
- The String representation.
-
identityToString
This method returns the same as if Object.toString() would not have been overridden in obj.Note that this isn't 100% secure as collisions can always happen with hash codes.
Copied from Object.hashCode():
As much as is reasonably practical, the hashCode method defined by class
Object
does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.)- Parameters:
obj
- the Object that is to be converted into an identity string.- Returns:
- the identity string as also defined in Object.toString()
-
toString
-
ParameterizedMessage(String, Object[], Throwable)
instead