You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Keith D Gregory (Jira)" <ji...@apache.org> on 2020/04/04 12:29:00 UTC
[jira] [Updated] (LOG4J2-2813) Questionable code order in
AbstractStringLayout.serializeToBytes()
[ https://issues.apache.org/jira/browse/LOG4J2-2813?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Keith D Gregory updated LOG4J2-2813:
------------------------------------
Description:
Source from [current master|https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java;h=76c00b235992e4316107c1727e0473e5043d565b;hb=HEAD#l280]:
{code:java}
protected byte[] serializeToBytes(final Serializer serializer, final byte[] defaultValue) {
final String serializable = serializeToString(serializer);
if (serializer == null) {
return defaultValue;
}
return StringEncoder.toBytes(serializable, getCharset());
}
{code}
I believe the test should be on "{{serializable}}" not "{{serializer}}".
was:
Source from [current master|https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java;h=76c00b235992e4316107c1727e0473e5043d565b;hb=HEAD#l280]:
{code:java}
protected byte[] serializeToBytes(final Serializer serializer, final byte[] defaultValue) {
final String serializable = serializeToString(serializer);
if (serializer == null) {
return defaultValue;
}
return StringEncoder.toBytes(serializable, getCharset());
}
{code}
The null check on {{serializer}} should either be moved above the {{serializeToString()}} invocation (which repeats it), or the test should be on "{{serializable}}" not "{{serializer}}".
> Questionable code order in AbstractStringLayout.serializeToBytes()
> ------------------------------------------------------------------
>
> Key: LOG4J2-2813
> URL: https://issues.apache.org/jira/browse/LOG4J2-2813
> Project: Log4j 2
> Issue Type: Improvement
> Components: Layouts
> Affects Versions: 2.13.1
> Reporter: Keith D Gregory
> Priority: Trivial
>
> Source from [current master|https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=blob;f=log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java;h=76c00b235992e4316107c1727e0473e5043d565b;hb=HEAD#l280]:
> {code:java}
> protected byte[] serializeToBytes(final Serializer serializer, final byte[] defaultValue) {
> final String serializable = serializeToString(serializer);
> if (serializer == null) {
> return defaultValue;
> }
> return StringEncoder.toBytes(serializable, getCharset());
> }
> {code}
> I believe the test should be on "{{serializable}}" not "{{serializer}}".
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)