Home > Software engineering >  class Test (in unnamed module @0x33f88ab) cannot access class com.sun.media.sound.FFT (in module jav
class Test (in unnamed module @0x33f88ab) cannot access class com.sun.media.sound.FFT (in module jav

Time:04-03

I want to use musicg to analysis audio fingerprint.
But I got following error in musicg library.

IllegalAccessError: class Test
(in unnamed module @0x33f88ab) cannot access class com.sun.media.sound.FFT
(in module java.desktop)
because module java.desktop does not export com.sun.media.sound to unnamed module @0x33f88ab

What should I do?

Environment

  • Kotlin
  • JDK 17(downgrade available)
  • musicg 1.4.2.2

My code

fun main(args: Array<String>) {
    FFT(10, 20)
}

got exception in FFT(10, 20)

CodePudding user response:

com.sun and its sub-packages are not part of the public Java API. They implement some standard Java APIs, but you shouldn't refer to them directly. (They're likely to change and/or be renamed or removed between JVM releases, and non-Sun/Oracle JVMs probably won't have them at all.)

In most cases you should access the public API classes (e.g. in javax.sound) instead. (Those may use sun.*/com.sun.*/etc. classes internally as needed, but that's merely an implementation detail.)

In early versions of Java, there was nothing to stop people using those internal implementation classes, and so some developers got into bad habits. But Java 9 added a module system, which restricts access to them. The error message you see is a result of that.

The details are in JEP 260. The intent was that there would be public APIs for all of the critical APIs that were being restricted. However, according to this Oracle forum page, the work wasn't completed, and so there are some internal APIs for which no public equivalent exists yet.

FFT looks like one of those classes that has been overlooked. I can't see a direct replacement for it, I'm afraid. Is there a third-party library you can use? This question gives some options.

  • Related