[ 
https://issues.apache.org/jira/browse/GOBBLIN-1826?focusedWorklogId=859325&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-859325
 ]

ASF GitHub Bot logged work on GOBBLIN-1826:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/Apr/23 06:51
            Start Date: 27/Apr/23 06:51
    Worklog Time Spent: 10m 
      Work Description: phet commented on code in PR #3688:
URL: https://github.com/apache/gobblin/pull/3688#discussion_r1178692889


##########
gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveRegistrationUnit.java:
##########
@@ -125,14 +125,13 @@ protected void populateSerDeFields(State state) {
   protected static <T> Optional<T> populateField(State state, String key, 
TypeToken<T> token) {
     if (state.contains(key)) {
       Optional<T> fieldValue;
-
-      if (new TypeToken<Boolean>() 
{}.getRawType().isAssignableFrom(token.getClass())) {
+      if (new TypeToken<Boolean>(){}.isSupertypeOf(token)) {
         fieldValue = (Optional<T>) Optional.of(state.getPropAsBoolean(key));
-      } else if (new TypeToken<Integer>() 
{}.getRawType().isAssignableFrom(token.getClass())) {
+      } else if (new TypeToken<Integer>(){}.isSupertypeOf(token)) {
         fieldValue = (Optional<T>) Optional.of(state.getPropAsInt(key));
-      } else if (new TypeToken<Long>() 
{}.getRawType().isAssignableFrom(token.getClass())) {
+      } else if (new TypeToken<Long>(){}.isSupertypeOf(token)) {
         fieldValue = (Optional<T>) Optional.of(state.getPropAsLong(key));
-      } else if (new TypeToken<List<String>>() 
{}.getRawType().isAssignableFrom(token.getClass())) {

Review Comment:
   I believe what happened [during the recent guava 20.0 
bump](https://github.com/apache/gobblin/pull/3669/files#diff-b846a4c4070e2ba285002541a89db7d267851d120a9cedc1360c4e91ae240eef)
 is that this became
   ```
   x.isAssignableFrom(y)
   // where:
   //   Class<List<?>> x
   //   Class<TypeToken<?>> y
   ```
   so it just fell through to `Optional.of(state.getProp(key))` on line 137
   
   is that your interpretation as well?



##########
gobblin-hive-registration/src/test/java/org/apache/gobblin/hive/HiveTableTest.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.hive;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.testng.annotations.Test;
+
+import junit.framework.Assert;
+
+import org.apache.gobblin.configuration.State;
+
+public class HiveTableTest {

Review Comment:
   wondering... could this not be a test of `HiveRegistrationUnit`, rather than 
its `HiveTable` derived type?





Issue Time Tracking
-------------------

    Worklog Id:     (was: 859325)
    Time Spent: 0.5h  (was: 20m)

> Fix bug in Hive registration code where fields could be miscasted in types
> --------------------------------------------------------------------------
>
>                 Key: GOBBLIN-1826
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-1826
>             Project: Apache Gobblin
>          Issue Type: Bug
>          Components: gobblin-core
>            Reporter: William Lo
>            Assignee: Abhishek Tiwari
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> After the Guava 20 upgrade, there was a major bug in the Hive registration 
> code where fields could be casted as an unexpected type in 
> HiveRegistrationUnit  
> {code:java}
> protected static <T> Optional<T> populateField(State state, String key, 
> TypeToken<T> token) {
>  {code}
> The field setter is returning an Optional generic, which allows the code to 
> compile but fail during runtime as the types are mismatched, leading to a 
> casting exception when reading the type e.g.
> {code:java}
>  java.lang.ClassCastException: java.lang.String cannot be cast to 
> java.lang.Long at 
> org.apache.gobblin.hive.metastore.HiveMetaStoreUtils.getTable(HiveMetaStoreUtils.java:111)
>  {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to