Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public boolean isInheritable() {
*/
@JsonCreator
public static @Nullable PredefinedPolicyTypes fromCode(int code) {
if (code >= REVERSE_CODE_MAPPING_ARRAY.length) {
if (code < 0 || code >= REVERSE_CODE_MAPPING_ARRAY.length) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
*/
package org.apache.polaris.core.policy;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.stream.Stream;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -53,4 +56,14 @@ public void testPredefinedPolicyTypeFromName(int code, String name, boolean isIn
Assertions.assertThat(policyType.getName()).isEqualTo(name);
Assertions.assertThat(policyType.isInheritable()).isEqualTo(isInheritable);
}

@Test
void fromCodeReturnsNullForNegative() {
assertThat(PolicyType.fromCode(-1)).isNull();
}

@Test
void fromNameReturnsNullForUnknown() {
assertThat(PolicyType.fromName("__unknown__")).isNull();
}
Comment on lines +65 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this test required for this fix ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily related, but good to have :)

}