[
https://issues.apache.org/jira/browse/ZOOKEEPER-5032?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Julian Chandra Sutadi updated ZOOKEEPER-5032:
---------------------------------------------
External issue URL: (was: https://github.com/apache/zookeeper/pull/2364)
> StatsTrack(byte[]) throws NullPointerException when quota node data is null
> ---------------------------------------------------------------------------
>
> Key: ZOOKEEPER-5032
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-5032
> Project: ZooKeeper
> Issue Type: Bug
> Components: quota
> Affects Versions: 3.9.5
> Reporter: Julian Chandra Sutadi
> Priority: Major
> Time Spent: 10m
>
> While conducting testing on the ZooKeeper 3.9.5 release, a possible
> NullPointerException was identified in the StatsTrack(byte[]) constructor.
> When the byte[] parameter is null, passing it directly to new String(stat,
> StandardCharsets.UTF_8) causes an NPE. A null byte array can occur when
> node.data is null for a quota znode.
> *Fix*
> Delegate to the existing StatsTrack(String) constructor with a null check:
> {code:java}
> public StatsTrack(byte[] stat) {
> this(stat == null ? null : new String(stat, StandardCharsets.UTF_8));
> // invokes constructor overload below
> }
> public StatsTrack(String stat) {
> this.stats.clear();
> if (stat == null || stat.length() == 0) {
> return;
> }
> ...
> }{code}
> *Testing*
> A regression test testConstructorWithNullByteArray is added to
> StatsTrackTest. StatsTrackTest is also migrated from JUnit 4 to JUnit 5 to
> align with the rest of the test suite, as it was previously not being
> executed by the surefire runner
--
This message was sent by Atlassian Jira
(v8.20.10#820010)