Skip to content

Conversation

@devCod3r
Copy link
Contributor

Fixes #4268

Motivation

Replaced the if-else statements with switch.
Issue #4268

Modifications

Replaced the if-else statements with switch.

Documentation

  • Does this pull request introduce a new feature?
  • Ans: No
  • If a feature is not applicable for documentation, explain why?
  • Ans: Only replaced the if-else statements with switch.

return SendMessageRequestProtocolResolver.buildEvent(header, body);
} else {
throw new ProtocolHandleException(String.format("unsupported requestCode: %s", requestCode));
switch (RequestCode.valueOf(requestCode)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

valueOf method is to transfer an Enum constant specified name to return an Enum constant.So It can not transfer requestCode as specified name to get any Enum constant.
image

So as the same as #4270.It causes client to fail to connect to the runtime server.
image

return SendMessageRequestProtocolResolver.buildEvent(header, body);
} else {
throw new ProtocolHandleException(String.format("unsupported requestCode: %s", requestCode));
switch (RequestCode.valueOf(requestCode)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, my mistake here, the valueof here returns the enum constant for the specified string value, here it is judged by the requestCode, so it won't match up by doing so.
You might consider writing a method in the RequestCode class that returns the corresponding Enum type constant based on the requestCode.

@codecov
Copy link

codecov bot commented Jul 28, 2023

Codecov Report

Merging #4298 (e2def87) into master (a48410c) will not change coverage.
Report is 6 commits behind head on master.
The diff coverage is n/a.

❗ Current head e2def87 differs from pull request most recent head d19baa5. Consider uploading reports for the commit d19baa5 to get more accurate results

@@            Coverage Diff            @@
##             master    #4298   +/-   ##
=========================================
  Coverage     16.35%   16.35%           
  Complexity     1359     1359           
=========================================
  Files           594      594           
  Lines         25419    25419           
  Branches       2394     2394           
=========================================
  Hits           4158     4158           
  Misses        20838    20838           
  Partials        423      423           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Alonexc
Copy link
Contributor

Alonexc commented Jul 28, 2023

This method already exists in this class, and the valueOf() method can be changed to get():
image

Also please fix pr #4270.

@pandaapo
Copy link
Member

pandaapo commented Aug 8, 2023

@devCod3r This pr brought a bug. Refer the #4298 (comment). If you are willing, you can post a new issue and pr to fix the bug.

@devCod3r devCod3r deleted the developmentEM branch August 9, 2023 13:13
xuhongjia pushed a commit to Deckers-Ohana/eventmesh that referenced this pull request Mar 13, 2025
[ISSUE apache#4268] Used switch to replace the if-else [CloudEventsProtocolAdaptor]
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.

[Enhancement] Use switch to replace the if-else.[CloudEventsProtocolAdaptor]

6 participants