Skip to content

Commit

Permalink
Remove some @SuppressWarnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed May 25, 2021
1 parent 1682277 commit 357951f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/apache/commons/lang3/ObjectUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1082,11 +1082,10 @@ public static <T> T median(final Comparator<T> comparator, final T... items) {
Validate.notEmpty(items, "null/empty items");
Validate.noNullElements(items);
Validate.notNull(comparator, "comparator");
final TreeSet<T> sort = new TreeSet<>(comparator);
Collections.addAll(sort, items);
final TreeSet<T> treeSet = new TreeSet<>(comparator);
Collections.addAll(treeSet, items);
@SuppressWarnings("unchecked") //we know all items added were T instances
final
T result = (T) sort.toArray()[(sort.size() - 1) / 2];
final T result = (T) treeSet.toArray()[(treeSet.size() - 1) / 2];
return result;
}

Expand Down
20 changes: 8 additions & 12 deletions src/main/java/org/apache/commons/lang3/SerializationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,17 @@ public static <T extends Serializable> T clone(final T object) {
final byte[] objectData = serialize(object);
final ByteArrayInputStream bais = new ByteArrayInputStream(objectData);

try (ClassLoaderAwareObjectInputStream in = new ClassLoaderAwareObjectInputStream(bais,
object.getClass().getClassLoader())) {
final Class<T> cls = ObjectUtils.getClass(object);
try (ClassLoaderAwareObjectInputStream in = new ClassLoaderAwareObjectInputStream(bais, cls.getClassLoader())) {
/*
* when we serialize and deserialize an object,
* it is reasonable to assume the deserialized object
* is of the same type as the original serialized object
* when we serialize and deserialize an object, it is reasonable to assume the deserialized object is of the
* same type as the original serialized object
*/
@SuppressWarnings("unchecked") // see above
final T readObject = (T) in.readObject();
return readObject;
return cls.cast(in.readObject());

} catch (final ClassNotFoundException ex) {
throw new SerializationException("ClassNotFoundException while reading cloned object data", ex);
} catch (final IOException ex) {
throw new SerializationException("IOException while reading or closing cloned object data", ex);
} catch (final ClassNotFoundException | IOException ex) {
throw new SerializationException(
String.format("%s while reading cloned object data", ex.getClass().getSimpleName()), ex);
}
}

Expand Down

0 comments on commit 357951f

Please sign in to comment.