AudioSynthesizer and other classes never made public after JEP260

SWinxy swinxythecat at gmail.com
Thu Jul 11 17:22:26 UTC 2024


I tried to dig into the archives for the two rotted links.

The first is a link to an email
<https://mail.openjdk.org/pipermail/audio-engine-dev/2007-October/000024.html>
from Florian Bomers on Oct 12, 2007. He thought the class should be public:

>> As a 1st step I suggest to create such interface in com.sun.media.sound
>> package, and them move it to javax.sound.midi.

> I don't see an advantage for going in 2 steps, I'd prefer to put
> it in javax.sound.midi directly.

I couldn't find the second link, though. It gives no hint as to where or
when it was emailed. It's likely in a jdk9 mailing list, but those are
extensive and the mail server doesn't have a search function.

If you *really* need it, and you are okay with hacking your way into places
where you shouldn't be, add --add-opens
java.desktop/com.sun.media.sound=ALL-UNNAMED as a VM argument. Then, the
following forbidden knowledge may work:

Class<?> synth = Class.forName("com.sun.media.sound.AudioSynthesizer");
Class<?> audio = Class.forName("com.sun.media.sound.SoftSynthesizer");

Method open = synth.getMethod("open", SourceDataLine.class, Map.class);
Constructor<?> declaredConstructor = audio.getDeclaredConstructor();
declaredConstructor.setAccessible(true);
Object o = declaredConstructor.newInstance();

open.setAccessible(true);
open.invoke(o, null, null);

It's horrible but it seems to work in my tests. I wouldn't advise this;
reflection to access protected classes is a Bad Idea.

SWinxy

On Fri, Jul 5, 2024 at 2:50 PM Aleksei Ivanov <alexey.ivanov at oracle.com>
wrote:

> Hi Ithinu,
>
> This message belongs in client-libs-dev mailing list.
>
> I see Dalibor's message, “It didn't get done in time for JDK 9.” Yet the
> link in his message is broken now.
>
> Let's see if anyone has more details.
>
> On 2024-07-04 23:53, Ithinu wrote:
> > Hi,
> >
> > AudioSynthesizer has a method open(line, config) which is the only way
> > of configuring its parameters and thus it seems
> > (https://bugs.openjdk.org/browse/JDK-6941027) that it was intended to
> > be made public. It is not the case in JDK 21. There were other useful
> > classes, like FFT, that are also no longer accessible.
> >
> > According to
> >
> https://forums.oracle.com/ords/apexds/post/com-sun-media-sound-in-java-9-0673
> > "it didn't get done in time for JDK 9".
> >
> > Is it plausible that someone will eventually look into that? Thanks.
> --
> Regards,
> Alexey
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20240711/fdaff93a/attachment-0001.htm>


More information about the client-libs-dev mailing list