Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCast Exception - ExecutionContextDataSource cannot be cast to java.lang.String #213

Open
abaratham-nlok opened this issue Sep 27, 2022 · 0 comments

Comments

@abaratham-nlok
Copy link

Hello,

I am getting a ClassCastException when running a RabbitMQTriggered Java function

Core Tools Version: 4.0.4785 Commit hash: N/A (64-bit)
Function Runtime Version: 4.10.4.19213

Gradle dependency versions and azurefunctions plugin config:

plugins {
    id 'java'
    id "com.microsoft.azure.azurefunctions" version "1.11.0"
}

apply plugin: 'java'
apply plugin: "com.microsoft.azure.azurefunctions"

group 'com.anand.dsr'
version '0.0.1-SNAPSHOT'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.1'
    implementation 'com.microsoft.azure.functions:azure-functions-java-library:2.0.1'
    implementation group: 'com.microsoft.azure.functions', name: 'azure-functions-java-library-rabbitmq', version: '2.0.1'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
    testImplementation "org.mockito:mockito-inline:4.1.0"
    testImplementation "org.mockito:mockito-junit-jupiter:4.1.0"
}

test {
    useJUnitPlatform()
}

azurefunctions {
    subscription = ''
    resourceGroup = ''
    appName = ''
    pricingTier = 'Consumption'
    region = 'eastus'
    runtime {
        os = 'linux'
    }
    localDebug = "transport=dt_socket,server=y,suspend=n,address=5005"
}

I have also tried downgrading the core tools and java runtime worker to version ~3, and azure-functions-java-library to 1.4.2.

Function definition:

    @FunctionName("requestProcessor")
    public void run(@RabbitMQTrigger(connectionStringSetting = "rabbitMQConnectionString", queueName = "dsr.test")
                                String inputMessage,
                    final ExecutionContext context)
    {
        context.getLogger().info("Successfully handled message: " + inputMessage);
    }

The error:

[2022-09-27T13:04:49.852Z] Exception: ClassCastException: com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource cannot be cast to java.lang.String
[2022-09-27T13:04:49.852Z] Stack: java.lang.ClassCastException: com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource cannot be cast to java.lang.String
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.binding.DataOperations.apply(DataOperations.java:99)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.binding.DataSource.computeByType(DataSource.java:56)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.binding.BindingDataStore.getDataByType(BindingDataStore.java:70)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:65)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:42)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.broker.JavaMethodExecutorImpl.execute(JavaMethodExecutorImpl.java:51)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:61)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
[2022-09-27T13:04:49.852Z]      at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
[2022-09-27T13:04:49.852Z]      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2022-09-27T13:04:49.852Z]      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2022-09-27T13:04:49.852Z]      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2022-09-27T13:04:49.852Z]      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2022-09-27T13:04:49.852Z]      at java.lang.Thread.run(Thread.java:750)

This seems to be happening because at runtime, ParameterResolver in the java worker library cannot find the @RabbitMQTrigger annotation to get the parameter name to map the inputMessage to a function parameter. I created my own @CustomTrigger annotation (below) and it started to work fine.

package com.microsoft.azure.functions.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface CustomTrigger {
    String name() default "inputMessage";
}
@abaratham-nlok abaratham-nlok changed the title Classcast Exception - ExecutionContextDataSource cannot be cast to java.lang.String ClassCast Exception - ExecutionContextDataSource cannot be cast to java.lang.String Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant