-
Notifications
You must be signed in to change notification settings - Fork 21
Ambiguous reference when invoking Properties.putAll() in Java 11 #10418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Another somewhat subtle issue: scala> import java.nio.ByteBuffer
import java.nio.ByteBuffer
scala> ByteBuffer.allocate(10)
res3: java.nio.ByteBuffer = java.nio.HeapByteBuffer[pos=0 lim=10 cap=10]
scala> res3.limit
<console>:15: error: ambiguous reference to overloaded definition,
both method limit in class ByteBuffer of type (x$1: Int)java.nio.ByteBuffer
and method limit in class Buffer of type ()Int
match expected type ?
res3.limit The |
I've made a |
and see also the umbrella JDK 9 ticket at scala/scala-dev#139 |
Compilation error fixes: - Avoid ambiguity error when appending to Properties in Scala code (scala/bug#10418) - Use position() and limit() to fix ambiguity issue ( scala/bug#10418 (comment)) - Disable findBugs if Java 9 is used ( findbugsproject/findbugs#105) Compilation warning fixes: - Avoid deprecated Class.newInstance in Utils.newInstance - Silence a few Java 9 deprecation warnings - var -> val and unused fixes Runtime error fixes: - Introduce Base64 class that works in Java 7 and Java 9 Also: - Set --release option if building with Java 9 Note that tests involving EasyMock (easymock/easymock#193) or PowerMock (powermock/powermock#783) will fail as neither supports Java 9 currently. Author: Ismael Juma <ismael@juma.me.uk> Reviewers: Jason Gustafson <jason@confluent.io> Closes #3647 from ijuma/kafka-4501-support-java-9
Please note the first bug exists in all versions of scala/java. Java 9 just happens to hit it with the change. // J.java
package j;
interface Bippy<A> {
public void f(Bippy<? extends A> t);
}
class J implements Bippy<Object> {
public void f(Bippy<?> t) { }
} // S.scala
package j
class S {
new J f new J
}
// a.scala:4: error: ambiguous reference to overloaded definition,
// both method f in class J of type (x$1: j.Bippy[_])Unit
// and method f in trait Bippy of type (x$1: j.Bippy[_ <: Object])Unit
// match argument types (j.J)
// new J f new J
// ^
// one error found Failing this way makes no sense because even if those types were distinct, you couldn't overload on them because they have the same erasure. But We have seen overriding-as-overloading over the imaginary distinction between Any and Object in the past, most prominently that |
Thanks Paul. I realise that the issue has existed for a while, but I thought it was worth pointing out that working Scala code breaks when upgrading to Java 9 due to this issue. |
@ijuma Oh, absolutely. I know you would already have known based on the nature of the bug that it wasn't specific to java 9, and tying it to java 9 is probably the way to get it fixed, but I didn't want the overall takeaway to be that it's a java 9 bug. |
This issue prevents the Scala.js test suite from being compiled, with zillions of issues of the form
This used to compile because Writing Independent reproduction: $ ~/opt/scala-2.12.3/bin/scala
Welcome to Scala 2.12.3 (Java HotSpot(TM) 64-Bit Server VM, Java 9).
Type in expressions for evaluation. Or try :help.
scala> val b = java.nio.ByteBuffer.allocate(5)
b: java.nio.ByteBuffer = java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]
scala> b.position
<console>:13: error: ambiguous reference to overloaded definition,
both method position in class ByteBuffer of type (x$1: Int)java.nio.ByteBuffer
and method position in class Buffer of type ()Int
match expected type ?
b.position
^
scala> b.position()
res1: Int = 0
scala> val c: java.nio.Buffer = b
c: java.nio.Buffer = java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]
scala> c.position
res2: Int = 0 whereas on Java 8: $ ~/opt/scala-2.12.3/bin/scala
Welcome to Scala 2.12.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_40).
Type in expressions for evaluation. Or try :help.
scala> val b = java.nio.ByteBuffer.allocate(5)
b: java.nio.ByteBuffer = java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]
scala> b.position
res0: Int = 0
scala> b.position()
res1: Int = 0
scala> val c: java.nio.Buffer = b
c: java.nio.Buffer = java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]
scala> c.position
res2: Int = 0 |
First, several methods of `nio.Buffer` are now overridden in specific subclasses so that they return a more specific type. For example, `Buffer.position(int)` is overridden in `ByteBuffer` to return a `ByteBuffer`, allowing chained invocations. This obviously means we had to add those overrides in our javalib, so that they can link. Indeed, the overrides have a different binary signature. In addition, because of scala/bug#10418, we also have to call `position()` and `limit()` instead of `position` and `limit`, respectively. Lastly, the methods `slice()` and `duplicate()` now have an abstract definition in `Buffer`, which broken source compatibility of the `BufferAdapter`s in our test suite. We fix this by renaming the methods to `sliceChain()` and `duplicateChain()` in the adapters.
First, several methods of `nio.Buffer` are now overridden in specific subclasses so that they return a more specific type. For example, `Buffer.position(int)` is overridden in `ByteBuffer` to return a `ByteBuffer`, allowing chained invocations. This obviously means we had to add those overrides in our javalib, so that they can link. Indeed, the overrides have a different binary signature. In addition, because of scala/bug#10418, we also have to call `position()` and `limit()` instead of `position` and `limit`, respectively. Lastly, the methods `slice()` and `duplicate()` now have an abstract definition in `Buffer`, which broken source compatibility of the `BufferAdapter`s in our test suite. We fix this by renaming the methods to `sliceChain()` and `duplicateChain()` in the adapters.
We have a special case in |
* Using non-deprecated valueOf Constructors for boxing types were mostly deprecated. For example: http://download.java.net/java/jdk9/docs/api/java/lang/Integer.html#Integer-int- * Remove uses os deprecated Class.newInstance See http://download.java.net/java/jdk9/docs/api/java/lang/Class.html#newInstance-- * Exception check compatible with Java 8 and 9 In Java 8 we get a java.net.SocketException but in Java 9 we got a more specific javax.net.ssl.SSLException with a SocketException as the cause. * Fix ambiguous call to putAll See scala/bug#10418
See: scala/scala-asm#5 Upstream changes in ASM: scala/scala-asm@ASM_6_0...ASM_6_2 http://asm.ow2.io/versions.html The motivations, other than just keeping current, are: - support for Java 9/10/11 updates to the classfile format. - reducing needless String => Array[Char] conversions thanks to internal changes in ASM. This PR will fail to build until we publish artifact from scala/scala-asm. Includes a workaround for scala/bug#10418
See: scala/scala-asm#5 Upstream changes in ASM: scala/scala-asm@ASM_6_0...ASM_6_2 http://asm.ow2.io/versions.html The motivations, other than just keeping current, are: - support for Java 9/10/11 updates to the classfile format. - reducing needless String => Array[Char] conversions thanks to internal changes in ASM. This PR will fail to build until we publish artifact from scala/scala-asm. Includes a workaround for scala/bug#10418
See: scala/scala-asm#5 Upstream changes in ASM: scala/scala-asm@ASM_6_0...ASM_6_2 http://asm.ow2.io/versions.html The motivations, other than just keeping current, are: - support for Java 9/10/11 updates to the classfile format. - reducing needless String => Array[Char] conversions thanks to internal changes in ASM. This PR will fail to build until we publish artifact from scala/scala-asm. Includes a workaround for scala/bug#10418
See: scala/scala-asm#5 Upstream changes in ASM: scala/scala-asm@ASM_6_0...ASM_6_2 http://asm.ow2.io/versions.html The motivations, other than just keeping current, are: - support for Java 9/10/11 updates to the classfile format. - reducing needless String => Array[Char] conversions thanks to internal changes in ASM. This PR will fail to build until we publish artifact from scala/scala-asm. Includes a workaround for scala/bug#10418
See: scala/scala-asm#5 Upstream changes in ASM: scala/scala-asm@ASM_6_0...ASM_6_2 http://asm.ow2.io/versions.html The motivations, other than just keeping current, are: - support for Java 9/10/11 updates to the classfile format. - reducing needless String => Array[Char] conversions thanks to internal changes in ASM. This PR will fail to build until we publish artifact from scala/scala-asm. Includes a workaround for scala/bug#10418
See: scala/scala-asm#5 Upstream changes in ASM: scala/scala-asm@ASM_6_0...ASM_6_2 http://asm.ow2.io/versions.html The motivations, other than just keeping current, are: - support for Java 9/10/11 updates to the classfile format. - reducing needless String => Array[Char] conversions thanks to internal changes in ASM. This PR will fail to build until we publish artifact from scala/scala-asm. Includes a workaround for scala/bug#10418
See: scala/scala-asm#5 Upstream changes in ASM: scala/scala-asm@ASM_6_0...ASM_6_2 http://asm.ow2.io/versions.html The motivations, other than just keeping current, are: - support for Java 9/10/11 updates to the classfile format. - reducing needless String => Array[Char] conversions thanks to internal changes in ASM. This PR will fail to build until we publish artifact from scala/scala-asm. Includes a workaround for scala/bug#10418
@ijuma Current stable release |
…eference ### What changes were proposed in this pull request? This PR aims to recover the JDK11 compilation with a workaround. For now, the master branch is broken like the following due to a [Scala bug](scala/bug#10418) which is fixed in `2.13.0-RC2`. ``` [ERROR] [Error] /spark/sql/core/src/main/scala/org/apache/spark/sql/execution/SQLExecutionRDD.scala:42: ambiguous reference to overloaded definition, both method putAll in class Properties of type (x$1: java.util.Map[_, _])Unit and method putAll in class Hashtable of type (x$1: java.util.Map[_ <: Object, _ <: Object])Unit match argument types (java.util.Map[String,String]) ``` - https://github.com/apache/spark/actions (JDK11 build monitoring) ### Why are the changes needed? This workaround recovers JDK11 compilation. ### Does this PR introduce any user-facing change? No. ### How was this patch tested? Manual build with JDK11 because this is JDK11 compilation fix. - Jenkins builds with JDK8 and tests with JDK11. - GitHub action will verify this after merging. Closes #25738 from dongjoon-hyun/SPARK-28939. Authored-by: Dongjoon Hyun <dhyun@apple.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
…eference ### What changes were proposed in this pull request? This PR aims to recover the JDK11 compilation with a workaround. For now, the master branch is broken like the following due to a [Scala bug](scala/bug#10418) which is fixed in `2.13.0-RC2`. ``` [ERROR] [Error] /spark/sql/core/src/main/scala/org/apache/spark/sql/execution/SQLExecutionRDD.scala:42: ambiguous reference to overloaded definition, both method putAll in class Properties of type (x$1: java.util.Map[_, _])Unit and method putAll in class Hashtable of type (x$1: java.util.Map[_ <: Object, _ <: Object])Unit match argument types (java.util.Map[String,String]) ``` - https://github.com/apache/spark/actions (JDK11 build monitoring) ### Why are the changes needed? This workaround recovers JDK11 compilation. ### Does this PR introduce any user-facing change? No. ### How was this patch tested? Manual build with JDK11 because this is JDK11 compilation fix. - Jenkins builds with JDK8 and tests with JDK11. - GitHub action will verify this after merging. Closes apache#25738 from dongjoon-hyun/SPARK-28939. Authored-by: Dongjoon Hyun <dhyun@apple.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
add round brackets to call on mark and position. With java 1.9+ methods that used to only be in the Buffer class are now also in the ByteBuffer class. This leads to ambiguous reference in scala. Problem description: scala/bug#10418 fixed it analogous to https://git.uni-due.de/embedded-systems-public/spark/commit/f41c0a93fd3913ad93e55ddbfd875229872ecc97
add round brackets to call on mark and position. With java 1.9+ methods that used to only be in the Buffer class are now also in the ByteBuffer class. This leads to ambiguous reference in scala. Problem description: scala/bug#10418 fixed it analogous to https://git.uni-due.de/embedded-systems-public/spark/commit/f41c0a93fd3913ad93e55ddbfd875229872ecc97
* Using non-deprecated valueOf Constructors for boxing types were mostly deprecated. For example: http://download.java.net/java/jdk9/docs/api/java/lang/Integer.html#Integer-int- * Remove uses os deprecated Class.newInstance See http://download.java.net/java/jdk9/docs/api/java/lang/Class.html#newInstance-- * Exception check compatible with Java 8 and 9 In Java 8 we get a java.net.SocketException but in Java 9 we got a more specific javax.net.ssl.SSLException with a SocketException as the cause. * Fix ambiguous call to putAll See scala/bug#10418
Scala bug workaround, see scala/bug#10418
### What changes were proposed in this pull request? This PR uses the `putAll` method of `Properties` class in place of `put`. ### Why are the changes needed? In Scala 2.13, scala/bug#10418 has been fixed. So we can avoid the workaround. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? There is no change in functionality. Existing tests suffice. ### Was this patch authored or co-authored using generative AI tooling? No Closes #48993 from tedyu/put-all. Authored-by: Zhihong Yu <yuzhihong@gmail.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
Java 8:
Java 9:
The reason is that the following override was added in Java 9 in order to use a ConcurrentHashMap as the underlying implementation:
scalac seems to think it's an overload instead of an override. The Hashtable method is defined as (K = Object and V = Object):
I found this while trying to compile Apache Kafka with Java 9.
Is it worth doing anything about this apart from documenting it somewhere?
The text was updated successfully, but these errors were encountered: