From b0675a9d26948cb3eeee2b20b5d870a54c796102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Vl=C4=8Dek?= Date: Tue, 2 Jul 2024 16:31:06 +0200 Subject: [PATCH] Addressing PR review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add FsInfo.Path ctor asserts. Signed-off-by: Lukáš Vlček --- .../java/org/opensearch/monitor/fs/FsInfo.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/monitor/fs/FsInfo.java b/server/src/main/java/org/opensearch/monitor/fs/FsInfo.java index f6879109c337f..67a2f6c43fc84 100644 --- a/server/src/main/java/org/opensearch/monitor/fs/FsInfo.java +++ b/server/src/main/java/org/opensearch/monitor/fs/FsInfo.java @@ -81,8 +81,8 @@ public static class Path implements Writeable, ToXContentObject { public Path() {} /** - * Please notice that this constructor will use value of 0 - * for fileCacheReserved and fileCacheUtilized variables. + * Please notice that this constructor will set value of 0 + * to fileCacheReserved and fileCacheUtilized variables. * * See {@link #getFileCacheReserved()}, {@link #getFileCacheUtilized()} */ @@ -90,6 +90,11 @@ public Path(String path, @Nullable String mount, long total, long free, long ava new Path(path, mount, total, free, available, 0, 0); } + /** + * Do not assign negative values to variables total, free, available, + * fileCacheReserved and fileCacheUtilized. The only exception is value -1 + * which is interpreted as an uninitialized value. + */ @InternalApi public Path( String path, @@ -107,6 +112,12 @@ public Path( this.available = available; this.fileCacheReserved = fileCacheReserved; this.fileCacheUtilized = fileCacheUtilized; + + assert (this.total == -1 || this.total >= 0) : "Total value can not be negative"; + assert (this.free == -1 || this.free >= 0) : "Free value can not be negative"; + assert (this.available == -1 || this.available >= 0) : "Available value can not be negative"; + assert (this.fileCacheReserved == -1 || this.fileCacheReserved >= 0) : "File cache reserved value can not be negative"; + assert (this.fileCacheUtilized == -1 || this.fileCacheUtilized >= 0) : "File cache utilization value can not be negative"; } /**