[
https://issues.apache.org/jira/browse/GOBBLIN-1826?focusedWorklogId=859417&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-859417
]
ASF GitHub Bot logged work on GOBBLIN-1826:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 27/Apr/23 14:42
Start Date: 27/Apr/23 14:42
Worklog Time Spent: 10m
Work Description: Will-Lo commented on code in PR #3688:
URL: https://github.com/apache/gobblin/pull/3688#discussion_r1179268362
##########
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:
Yup that's what happened, shouldn't have taken the raw type unless I was
also getting the raw type from the incoming token as well.
Issue Time Tracking
-------------------
Worklog Id: (was: 859417)
Time Spent: 40m (was: 0.5h)
> 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: 40m
> 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)