是否有人对此代码为何在Java 8上起作用,但在Java 9上没有洞察力
String[] strings = (String[]) Arrays.asList("foo", "bar").toArray();
for (String string : strings) {
System.out.println(string);
}
,我知道我们可以在执行Toarray时指定类型而不是施放。但是我在调试我们的
Does anyone have insights on why this code works on java 8 but not on java 9
String[] strings = (String[]) Arrays.asList("foo", "bar").toArray();
for (String string : strings) {
System.out.println(string);
}
I understand we can specify the type while doing toArray instead of casting it. But I found this issue while debugging one of our dependency (hive-metastore-2.1.1 HiveMetaStoreClient line 274). So I don't have the liberty to change the code and we are running java 9. Is there a way to get around this? Is this a problem with java 9(since it seems like a breaking change) or just file a bug in the hive repo.
发布评论
评论(2)
似乎这可能是由于更改(coll)arrays.aslist.aslist(x).toArray(x).toArray( ).getClass()应该是对象[]。class
看起来他们修复了toarray可以返回对象以外的类型的错误。
引用发行笔记
因此,似乎您需要在Hive Repo中提交错误才能更新此更改后的代码以工作。
看起来他们实际上在未来的提交中添加了一个配置值,如果设置具有一定值的设置,则实际上避免了代码路径引起问题。
https://github.com/apache/hive/commit/07492e0d2f1942c1794a3190610e10207c850cf7#diff-ca39aa4869cc58909a31c761cd7a27ccR257
也许您可以升级到具有此版本的版本,并使用此配置来避免问题。只要您不在乎需要该代码路径的功能。似乎引起问题的代码是选择要随机使用的URI,而不仅仅是从列表中选择第一个URI。
Seems like it might be due to the change (coll) Arrays.asList(x).toArray().getClass() should be Object[].class
Looks like they fixed a bug that toArray could return types other than Object.
Quoting the release notes
So it seems like you'll need to file a bug in the Hive repo to update the code to work after this change.
Looks like they actually added a configuration value in a future commit which if set with a certain value would actually avoid the code path causing the issue.
https://github.com/apache/hive/commit/07492e0d2f1942c1794a3190610e10207c850cf7#diff-ca39aa4869cc58909a31c761cd7a27ccR257
Maybe you can upgrade to a version that has this and use this configuration to avoid the problem. So long as you don't care about the functionality that requires that code path. Seems like the code causing the problem is selecting which URI to use randomly instead of just picking the first one out of a list.
arrays.arraylist.toArray的实现似乎已经更改。 clone
衬里数组:新实现强迫返回的数组为
object []
:to to to to to但是,要清楚,在Java 8中,演员阵容之所以起作用,是因为备用数组最初是
string []
,由aslist
varargs创建。隐含发生的所有发生的是new String [] {“ foo”,“ bar”}。clone()
,但是数组通过aslist
列表传递。
实现。至于修复破裂的依赖性,我认为除了使用Java 8运行时环境或重写该提交中引入的内容外,没有一种方法。提交错误报告似乎是正确的做法。
The implementation of
Arrays.ArrayList.toArray
seems to have been changed. The old implementation was to justclone
the backing array:The new implementation forces the returned array to be an
Object[]
:To be clear, though, in Java 8 the cast only worked because the backing array was originally a
String[]
, created by theasList
varargs. Implicitly all that was happening wasnew String[] {"foo", "bar"}.clone()
, but the array was passed through theasList
List
implementation.As for fixing the broken dependency, I don't think there's a way besides either using a Java 8 run-time environment or rewriting what was introduced in that commit. Filing a bug report seems like the right thing to do.