Skip to content

resolve the payload type from the class declaration - #421

Open
rootkiller6788 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
rootkiller6788:fix-background-function-subclass-type
Open

rootkiller6788 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
rootkiller6788:fix-background-function-subclass-type

Conversation

@rootkiller6788

Copy link
Copy Markdown

Fixes #95.

A function that extends a base class implementing accept() for all its subclasses would not start, with "Could not determine the payload type for BackgroundFunction of type ...".

Reason is that the payload type was read off the accept method, but a subclass that does not declare accept itself only has the inherited, erased accept(Object, Context), so the lookup came back empty.

The type argument of BackgroundFunction is now read from the class declaration, walking up the hierarchy and substituting type variables on the way. That covers the inherited accept case and generic base classes, and if the declaration does not pin the type down (raw implementations, for example) it still falls back to the old accept lookup, so nothing that worked before changes.

Tests added for the inherited case and for two levels of inheritance; both fail without the change. On my machine the rest of the invoker/core suite fails the same way before and after.

When the accept method lives in a base class, the subclass only has the
erased accept(Object, Context), so the payload type comes out empty. This
test fails right now.
The accept method alone is not enough: if the subclass inherits accept from a
base class, the only copy it has is the erased accept(Object, Context), so we
could not tell what the payload type was. Read the type argument of
BackgroundFunction<T> by walking the class hierarchy instead, substituting
type variables as we go up. The accept method lookup is still there as a
fallback for classes where the declaration does not say.

Fixes GoogleCloudPlatform#95.
@rootkiller6788
rootkiller6788 marked this pull request as ready for review November 26, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BackgroundFunctionExecutor.java failes to detect type when sub-classed

1 participant