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

Fix: Type Casting Issue on GraphQL invocation #12340

Merged
merged 1 commit into from
Mar 22, 2024

Conversation

BLasan
Copy link
Contributor

@BLasan BLasan commented Mar 20, 2024

Purpose

Following error was returned on a graphql api invocation

[2024-03-20 20:16:43,230] ERROR - ServerWorker Error processing POST request for : /swapi/1.0.0.
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Long (java.lang.Integer and java.lang.Long are in module java.base of loader 'bootstrap')
	at org.wso2.carbon.apimgt.gateway.utils.GatewayUtils.generateAuthenticationContext_aroundBody46(GatewayUtils.java:739) ~[org.wso2.carbon.apimgt.gateway_9.29.47.jar:?]
	at org.wso2.carbon.apimgt.gateway.utils.GatewayUtils.generateAuthenticationContext(GatewayUtils.java:1) ~[org.wso2.carbon.apimgt.gateway_9.29.47.jar:?]
	at org.wso2.carbon.apimgt.gateway.handlers.security.apikey.ApiKeyAuthenticator.authenticate_aroundBody4(ApiKeyAuthenticator.java:170) ~[org.wso2.carbon.apimgt.gateway_9.29.47.jar:?]
	at org.wso2.carbon.apimgt.gateway.handlers.security.apikey.ApiKeyAuthenticator.authenticate(ApiKeyAuthenticator.java:1) ~[org.wso2.carbon.apimgt.gateway_9.29.47.jar:?]
	at org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler.isAuthenticate_aroundBody60(APIAuthenticationHandler.java:567) ~[org.wso2.carbon.apimgt.gateway_9.29.47.jar:?]
	at org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler.isAuthenticate(APIAuthenticationHandler.java:1) ~[org.wso2.carbon.apimgt.gateway_9.29.47.jar:?]
	at org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler.handleRequest_aroundBody50(APIAuthenticationHandler.java:435) ~[org.wso2.carbon.apimgt.gateway_9.29.47.jar:?]
	at org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler.handleRequest(APIAuthenticationHandler.java:1) ~[org.wso2.carbon.apimgt.gateway_9.29.47.jar:?]
	at org.apache.synapse.api.API.process(API.java:407) ~[synapse-core_4.0.0.wso2v94.jar:4.0.0-wso2v94]
	at org.apache.synapse.api.AbstractApiHandler.apiProcessNonDefaultStrategy(AbstractApiHandler.java:109) ~[synapse-core_4.0.0.wso2v94.jar:4.0.0-wso2v94]
	at org.apache.synapse.api.AbstractApiHandler.identifyAPI(AbstractApiHandler.java:129) ~[synapse-core_4.0.0.wso2v94.jar:4.0.0-wso2v94]
	at org.apache.synapse.api.AbstractApiHandler.dispatchToAPI(AbstractApiHandler.java:61) ~[synapse-core_4.0.0.wso2v94.jar:4.0.0-wso2v94]
	at org.apache.synapse.api.rest.RestRequestHandler.dispatchToAPI(RestRequestHandler.java:90) ~[synapse-core_4.0.0.wso2v94.jar:4.0.0-wso2v94]
	at org.apache.synapse.api.rest.RestRequestHandler.process(RestRequestHandler.java:76) ~[synapse-core_4.0.0.wso2v94.jar:4.0.0-wso2v94]
	at org.apache.synapse.rest.RESTRequestHandler.process(RESTRequestHandler.java:54) ~[synapse-core_4.0.0.wso2v94.jar:4.0.0-wso2v94]
	at org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:350) ~[synapse-core_4.0.0.wso2v94.jar:4.0.0-wso2v94]
	at org.apache.synapse.core.axis2.SynapseMessageReceiver.receive(SynapseMessageReceiver.java:101) ~[synapse-core_4.0.0.wso2v94.jar:4.0.0-wso2v94]
	at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180) ~[axis2_1.6.1.wso2v76.jar:?]
	at org.apache.synapse.transport.passthru.ServerWorker.processNonEntityEnclosingRESTHandler(ServerWorker.java:401) ~[synapse-nhttp-transport_4.0.0.wso2v94.jar:?]
	at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:460) ~[synapse-nhttp-transport_4.0.0.wso2v94.jar:?]
	at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:208) ~[synapse-nhttp-transport_4.0.0.wso2v94.jar:?]
	at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172) ~[axis2_1.6.1.wso2v76.jar:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
	at java.lang.Thread.run(Thread.java:829) ~[?:?]

Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 47.31%. Comparing base (ae5a694) to head (7d367cd).
Report is 122 commits behind head on master.

Files Patch % Lines
...wso2/carbon/apimgt/gateway/utils/GatewayUtils.java 0.00% 10 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master   #12340       +/-   ##
=============================================
+ Coverage     20.46%   47.31%   +26.85%     
- Complexity        0     4131     +4131     
=============================================
  Files          1223     1840      +617     
  Lines        105124   136475    +31351     
  Branches      14732    19757     +5025     
=============================================
+ Hits          21516    64579    +43063     
+ Misses        80775    64280    -16495     
- Partials       2833     7616     +4783     
Flag Coverage Δ
integration_tests 42.04% <0.00%> (?)
unit_tests 20.43% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -734,9 +734,9 @@ public static AuthenticationContext generateAuthenticationContext(String tokenSi
;
}
if (synCtx != null && APIConstants.GRAPHQL_API.equals(synCtx.getProperty(APIConstants.API_TYPE))) {
Integer graphQLMaxDepth = (int) (long) subscriptionTierObj.get(GraphQLConstants.GRAPHQL_MAX_DEPTH);
Integer graphQLMaxDepth = ((Number) subscriptionTierObj.get(GraphQLConstants.GRAPHQL_MAX_DEPTH)).intValue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to add a null check for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@BLasan BLasan force-pushed the fix-casting-issue branch from 3db9ece to 7d367cd Compare March 21, 2024 10:22
@BLasan BLasan merged commit 0cc31f8 into wso2:master Mar 22, 2024
8 of 9 checks passed
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.

2 participants