Skip to content

Commit

Permalink
OAK-11359: Remove usage of Guava Ints.checkedCast (#1957)
Browse files Browse the repository at this point in the history
  • Loading branch information
reschke authored Jan 8, 2025
1 parent c15d389 commit 651b6d7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.List;

import org.apache.jackrabbit.guava.common.io.ByteStreams;
import org.apache.jackrabbit.guava.common.primitives.Ints;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
Expand Down Expand Up @@ -312,7 +311,7 @@ public void copyBytes(DataInput input, long numBytes) throws IOException {

private static int determineBlobSize(NodeBuilder file){
if (file.hasProperty(OakDirectory.PROP_BLOB_SIZE)){
return Ints.checkedCast(file.getProperty(OakDirectory.PROP_BLOB_SIZE).getValue(Type.LONG));
return Math.toIntExact(file.getProperty(OakDirectory.PROP_BLOB_SIZE).getValue(Type.LONG));
}
return DEFAULT_BLOB_SIZE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void invalidQueryFilterRegex() throws CommitFailedException {
root.commit();
}

@Test(expected = IllegalArgumentException.class)
@Test(expected = RuntimeException.class)
public void invalidBlobSize() throws CommitFailedException {
Tree def = createIndexNodeAndData();
// 1L + Integer.MAX_VALUE results in IllegalArgumentException: Out of range: 2147483648
Expand All @@ -140,7 +140,7 @@ public void negativeBlobSize() throws CommitFailedException {
assertQuery(query, List.of("/tmp/testNode"));
}

@Test(expected = IllegalArgumentException.class)
@Test(expected = RuntimeException.class)
public void invalidMaxFieldLength() throws CommitFailedException {
Tree def = createIndexNodeAndData();
// 1L + Integer.MAX_VALUE results in IllegalArgumentException: Out of range: 2147483648
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.plugins.index.search;

import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.primitives.Ints;
import org.apache.jackrabbit.oak.api.IllegalRepositoryStateException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Root;
Expand Down Expand Up @@ -1892,7 +1890,7 @@ private static IndexFormatVersion determineVersionForFreshIndex(PropertyState fu
}

private static IndexFormatVersion versionFrom(PropertyState ps) {
return IndexFormatVersion.getVersion(Ints.checkedCast(ps.getValue(Type.LONG)));
return IndexFormatVersion.getVersion(Math.toIntExact(ps.getValue(Type.LONG)));
}

private static boolean hasIndexingRules(NodeState defn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.jackrabbit.oak.plugins.index.search.util;

import java.util.Collections;

import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.primitives.Ints;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.PropertyState;
Expand Down Expand Up @@ -51,7 +49,7 @@ public static boolean getOptionalValue(NodeState definition, String propName, bo
public static int getOptionalValue(NodeState definition, String propName, int defaultVal) {
try {
PropertyState ps = definition.getProperty(propName);
return ps == null ? defaultVal : Ints.checkedCast(ps.getValue(Type.LONG));
return ps == null ? defaultVal : Math.toIntExact(ps.getValue(Type.LONG));
} catch (IllegalStateException e) {
throw new IllegalStateException(String.format(ILLEGAL_STATE_EXCEPTION_ERROR_MESSAGE, propName), e);
}
Expand Down

0 comments on commit 651b6d7

Please sign in to comment.