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

IllegalStateException thrown from Service#restart()

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7u6
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Environment:

      JavaFX 2.2b3 32-bit, Windows 7 64-bit

      Description

      When calling restart() of a Service when its current state is "SCHEDULED", I get an IllegalStateException thrown at me included at the bottom of this description. No such exception is documented however.

      This seems to happen because internally an assumption is made that the FutureTask being cancelled usually returns "true" from its cancel method. However, this doesn't always seem to be the case, in which case the task's State is not updated and the reset() method called fails its assertion.

      Expected behaviour would be to always restart the Service, no matter what the State of the Service currently is.

      In my log I can clearly see this exception being thrown if the State is "SCHEDULED" (I put a print just in front of it). It is also clear from my log that this task was "restarted" just milliseconds before and restarted again a few milliseconds later (this is because the focus is changed twice in rapid succession causing my AsyncImageProperty to load a new image by means of this Service in the background).

      Relevant snipped from code:

        private void loadImageInBackground(ImageHandle imageHandle) {
          synchronized(imageLoadService) {
            if(imageHandle != null) {
              imageLoadService.setImageHandle(imageHandle);
              System.err.println(">>> hashcode " + this.hashCode() + " current state before restart: " + imageLoadService.getState());
              imageLoadService.restart(); // IllegalStateException here in some cases
            }
          }
        }


      >>> hashcode 3117123 current state before restart: SUCCEEDED
      >>> hashcode 19264094 current state before restart: SUCCEEDED
      >>> hashcode 3117123 current state before restart: SCHEDULED
      java.lang.IllegalStateException
      at javafx.concurrent.Service.reset(Service.java:521)
      at javafx.concurrent.Service.restart(Service.java:508)
      at hs.mediasystem.beans.AsyncImageProperty.loadImageInBackground(AsyncImageProperty.java:45)
      at hs.mediasystem.beans.AsyncImageProperty.access$1(AsyncImageProperty.java:40)
      at hs.mediasystem.beans.AsyncImageProperty$2.changed(AsyncImageProperty.java:32)
      at hs.mediasystem.beans.AsyncImageProperty$2.changed(AsyncImageProperty.java:1)
      at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:196)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
      at javafx.beans.binding.ObjectBinding.invalidate(ObjectBinding.java:170)
      at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.invalidated(SelectBinding.java:409)
      at javafx.beans.WeakInvalidationListener.invalidated(WeakInvalidationListener.java:80)
      at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:359)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
      at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:123)
      at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:130)
      at javafx.beans.property.ObjectPropertyBase.access$100(ObjectPropertyBase.java:69)
      at javafx.beans.property.ObjectPropertyBase$Listener.invalidated(ObjectPropertyBase.java:239)
      at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:359)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
      at javafx.beans.binding.ObjectBinding.invalidate(ObjectBinding.java:170)
      at com.sun.javafx.binding.BindingHelperObserver.invalidated(BindingHelperObserver.java:71)
      at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:155)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
      at javafx.beans.property.ReadOnlyObjectWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyObjectWrapper.java:195)
      at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:161)
      at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:130)
      at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:163)
      at javafx.scene.control.FocusModel.setFocusedItem(FocusModel.java:92)
      at javafx.scene.control.FocusModel$1.invalidated(FocusModel.java:55)
      ... rest snipped ...

        Attachments

          Activity

            People

            • Assignee:
              rbair Richard Bair
              Reporter:
              jhendrikx John Hendrikx
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: