From d64736d58965722b71d6eade578b6c4c266e6448 Mon Sep 17 00:00:00 2001 From: Daniel Templeton Date: Mon, 30 Oct 2017 12:40:29 -0700 Subject: [PATCH] YARN-7336. Unsafe cast from long to int Resource.hashCode() method (Contributed by Miklos Szegedi via Daniel Templeton) --- .../java/org/apache/hadoop/yarn/api/records/Resource.java | 4 ++-- .../hadoop/yarn/api/records/impl/LightWeightResource.java | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java index 796b6662dd..6bdde180e6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java @@ -463,11 +463,11 @@ public String toString() { @Override public int hashCode() { final int prime = 47; - long result = 0; + int result = 0; for (ResourceInformation entry : resources) { result = prime * result + entry.hashCode(); } - return (int) result; + return result; } /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java index a64d242a4a..7b07bbd949 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/impl/LightWeightResource.java @@ -155,9 +155,6 @@ public int compareTo(Resource other) { @Override public int hashCode() { final int prime = 47; - long result = prime + getMemorySize(); - result = prime * result + getVirtualCores(); - - return (int) result; + return prime * (prime + Long.hashCode(getMemorySize())) + getVirtualCores(); } }