Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8139153

MidiSystem.getMidiDeviceInfo() caches indefinitely on OSX

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u60
    • Fix Version/s: tbd_major
    • Component/s: client-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      $ java -version
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin fugalh-mbp1 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64 i386 MacBookPro11,2 Darwin


      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Macbook Pro
      The MIDI device I'm testing with is a Novation Launchpad Mini (USB), but I have also observed it with 3 other USB MIDI devices and virtual MIDI devices like that created by the Midi Keys app.

      A DESCRIPTION OF THE PROBLEM :
      MidiSystem.getMidiDeviceInfo() should return the device info objects for each midi device in the system (or maybe two, for devices that support both input and output). It does this, but it only scans the system once per JVM instance, and devices added or removed after the first call to getMidiDeviceInfo() are not reflected in the results.

      The first call takes a few seconds, and subsequent calls return quickly. All of these behaviors are consistent with a caching strategy.

      This question arises on Stack Overflow, where it is suggested to call com.sun.media.sound.JDK13Services.setCachingPeriod, however that function no longer exists and the API docs for JDK13Services say it is only for testing anyway. Also, it seems that the default value for that caching parameter should be 60 seconds, but waiting for many minutes does not change the caching behavior.

      http://stackoverflow.com/questions/3752352/java-sound-api-scanning-for-midi-devices

      I have tested the same code on Windows 10 and Ubuntu, where it works fine. I observe the same initial delay and subsequent speedup, however new devices do show up when plugged in. So this seems to be an OSX-specific bug.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The test program included in this bug report will illustrate the problem.

      While this program is running, add and/or remove midi devices and observe that the list does not change. Kill it and run it afresh and notice that the currently-correct list of devices is now shown.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When I plug in a new MIDI device, it should show up in the results the next time (or after a reasonable caching delay). When I remove a MIDI device it should not show up in the results.
      ACTUAL -
      The same results with each call, irrelevant of actual MIDI configuration.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.sound.midi.*;

      class Foo {
          public static void main(String[] args) throws InterruptedException {
              while (true) {
                  MidiDevice.Info[] a = MidiSystem.getMidiDeviceInfo();
                  for (MidiDevice.Info i : a) {
                      System.out.println(i.getName());
                  }
                  System.out.println();
                  Thread.sleep(2000);
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I am not aware of a workaround.

      1. main.m
        1 kB
        Sergey Bylokhov

        Activity

        Hide
        scfitch Stephen Fitch added a comment -
        Moving from JI to JDK for Dev evaluation - for 9, and possible 8-bp.
        Show
        scfitch Stephen Fitch added a comment - Moving from JI to JDK for Dev evaluation - for 9, and possible 8-bp.
        Hide
        serb Sergey Bylokhov added a comment -
        The cache in the JDK13Services was removed 8u20. It should be investigated why the list of device is not updated on osx.
        Show
        serb Sergey Bylokhov added a comment - The cache in the JDK13Services was removed 8u20. It should be investigated why the list of device is not updated on osx.
        Hide
        serb Sergey Bylokhov added a comment - - edited
        On OSX the number of devices is cached somewhere on the OS level. The MIDIGetNumberOfSources[1] always return the same number after application starts. MIDIRestart() does not help.

        [1] https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CACoreMIDIRef/MIDIServices/CompositePage.html#//apple_ref/c/func/MIDIGetNumberOfSources


        Same bug:
        http://www.juce.com/forum/topic/how-update-midi-device
        Show
        serb Sergey Bylokhov added a comment - - edited On OSX the number of devices is cached somewhere on the OS level. The MIDIGetNumberOfSources[1] always return the same number after application starts. MIDIRestart() does not help. [1] https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CACoreMIDIRef/MIDIServices/CompositePage.html#//apple_ref/c/func/MIDIGetNumberOfSources Same bug: http://www.juce.com/forum/topic/how-update-midi-device
        Hide
        serb Sergey Bylokhov added a comment -
        Bug filed to Apple: 24030635
        Show
        serb Sergey Bylokhov added a comment - Bug filed to Apple: 24030635
        Hide
        serb Sergey Bylokhov added a comment -
        The native test is attached
        Show
        serb Sergey Bylokhov added a comment - The native test is attached

          People

          • Assignee:
            serb Sergey Bylokhov
            Reporter:
            webbuggrp Webbug Group
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: