Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3213

Ambiguous setter in Image component

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 8.0.3
    • 8.0.1.1
    • Components
    • Security Level: Jimmy
    • None
    • ZK 8.0.3 S4

      depending on the JDK version the attached example image_content_bind.zul may cause the following exception due to ambiguous setters. Since the order of methods returned by the relection API is undefined either method can be called:
      (https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getMethods--)

      Image.setContent(org.zkoss.image.Image image) -> ignores null values (no problem)
      Image.setContent(RenderedImage image) -> fails on null values (exception below)

          image == null!
      Caused by:
      
      java.lang.IllegalArgumentException: image == null!
      	at javax.imageio.ImageTypeSpecifier.createFromRenderedImage(ImageTypeSpecifier.java:925)
      	at javax.imageio.ImageIO.getWriter(ImageIO.java:1591)
      	at javax.imageio.ImageIO.write(ImageIO.java:1578)
      	at org.zkoss.image.encoder.PNGEncoder.encode(PNGEncoder.java:35)
      	at org.zkoss.image.Images.encode(Images.java:66)
      	at org.zkoss.zul.Image.setContent(Image.java:224)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at org.zkoss.lang.reflect.Fields.set(Fields.java:153)
      	at org.zkoss.bind.impl.PropertyExpression.setValue(PropertyExpression.java:75)
      	at org.zkoss.bind.impl.LoadPropertyBindingImpl.load(LoadPropertyBindingImpl.java:90)
      

      possible solutions:

      1. avoid ambiguous setters
      2. handle null values consistently in both methods
      3. remove the setter depending on an AWT class since a helper class already exists to convert the AWT Rendered image to a org.zkoss.image.Image
      (Images.encode("a.png", image))

            wenninghsu wenninghsu
            cor3000 cor3000
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours
                3h