Annotate or use template classes for InvocationHandlers in the webview support library? |
||
Issue description
When using InvocationHandlers representing many different objects it's very easy to make mistakes by creating an InvocationHandler for the wrong object, e.g. the method
class SupportLibServiceWorkerControllerAdapter:
public InvocationHandler getServiceWorkerWebSettings()
should return an InvocationHandler representing ServiceWorkerWebSettingsBoundaryInterface, but we currently have no (compile-time) mechanism to ensure the returned InvocationHandler represents a ServiceWorkerWebSettingsBoundaryInterface.
You could for example implement getServiceWorkerWebSettings in the following way without compilation errors:
public InvocationHandler getServiceWorkerWebSettings() {
return BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
mAwServiceWorkerController.getAwServiceWorkerSettings()); // Wrong, this is an AwServiceWorkerSettings object, not a ServiceWorkerWebSettingsBoundaryInterface
}
One possibility here would be to have BoundaryInterfaceReflectionUtil.createInvocationHandlerFor return a new class implementing InvocationHandler:
TemplatedInvocationHandler<BoundaryInterface>
which declares a specific boundary interface as template, to ensure we type-check InvocationHandlers.
An alternative could be to use some kind of annotation for each invocationhandler.
Nate, WDYT?
,
May 11 2018
Agree with that statement - we should keep the InvocationHandlers clean
,
May 11 2018
Yeah I think the presubmit check is the best approach rather than making the types more complex here.
,
May 15 2018
Marking this as Won't fix given the presubmit check approach. |
||
►
Sign in to add a comment |
||
Comment 1 by ntfschr@chromium.org
, May 11 2018