Skip to content

Class cast exception in BatchPublisherWithContext or MappedBatchPublisherWithContext #208

Open
@bbakerman

Description

@bbakerman

Describe the bug
The two reactive batch loaders that take a context object throw a class cast exception if used.

The reason this is happening is that these methods missed the specific XXXContext methods and hence it falls through them and tries to cast them to BatchLoader


    private boolean isPublisher() {
        return batchLoadFunction instanceof BatchPublisher;
    }

    private boolean isMappedPublisher() {
        return batchLoadFunction instanceof MappedBatchPublisher;
    }

it should be

   private boolean isMappedPublisher() {
        return batchLoadFunction instanceof MappedBatchPublisher || batchLoadFunction instanceof MappedBatchPublisherWithContext;
    }


**To Reproduce**

Kotlin example below but the same would happen in Java

    val batchLoadFunction = MappedBatchPublisherWithContext<String, String?>
    { keys, subscriber, env ->
        val map: Map<String, String?> = keys.associateBy({ it })
        Flux.fromIterable(map.entries).subscribe(subscriber);
    }

    val dataLoader: DataLoader<String, String?> = DataLoaderFactory.newMappedPublisherDataLoader(batchLoadFunction)

    val cfA = dataLoader.load("A")
    val cfB = dataLoader.load("B")

    dataLoader.dispatch()

    assert(cfA.join().equals("A"))
    assert(cfB.join().equals("B"))


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions