Uploaded image for project: 'Beam'
  1. Beam
  2. BEAM-308

PipelineOptions throws when using package-private PipelineOptions interfaces from multiple packages

    XMLWordPrintableJSON

Details

    Description

      If a PipelineOptions instance is used as multiple PipelineOptions package-private interfaces from different packages, PipelineOptions.as will throw an exception:

      java.lang.IllegalArgumentException: non-public interfaces from different packages

      at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:652)
      at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:592)
      at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:244)
      at java.lang.reflect.WeakCache.get(WeakCache.java:141)
      at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:455)
      at java.lang.reflect.Proxy.getProxyClass(Proxy.java:405)
      at org.apache.beam.sdk.options.PipelineOptionsFactory.validateWellFormed(PipelineOptionsFactory.java:620)
      at org.apache.beam.sdk.options.ProxyInvocationHandler.as(ProxyInvocationHandler.java:209)
      at org.apache.beam.sdk.options.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:135)
      at com.sun.proxy.$Proxy6.as(Unknown Source)

      This fails because ProxyInvocationHandler attempts to create a Java Proxy object implementing the full set of interfaces, which has the restriction:

      All non-public interfaces must be in the same package; otherwise, it would not be possible for the proxy class to implement all of the interfaces, regardless of what package it is defined in.

      This can be triggered in a couple edge-case scenarios:

      1. PipelineOptions.as is called on the same PipelineOptions instance with multiple package-private interfaces.
      2. PipelineOptionsFactory.register is called with a package-private interface, and then PipelineOptions.as is called with a different package-private instance.

      We hit the second scenario in DataflowSDK unit tests. It's hard to trigger, but possible.


      I propose we make the behavior for package-private options explicit:

      1. Give a better exception message if we hit this issue in PipelineOptions.as listing the non-public interfaces and what packages they're in.
      2. Explicitly reject non-public interfaces from PipelineOptionsFactory.register, since this state is global and is easier to cause issues.

      Attachments

        Activity

          People

            lcwik Luke Cwik
            swegner Scott Wegner
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1.5h
                1.5h