The wrong log type is used for log printing during error handling

Open Beginner friendly
#670 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java
Domain
backend

Research direction

Start in org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer#doConvertMessage and inspect the catch block around message conversion. Change the conversion-failure logging to the requested error-level form, then verify that the RuntimeException behavior remains unchanged and run the relevant existing tests.

Written by the indexing model from the issue text.

Description

environment

<dependency>
      <groupId>org.apache.rocketmq</groupId>
      <artifactId>rocketmq-spring-boot-starter</artifactId>
      <version>2.3.0</version>
</dependency>

current latest version also has issue.

describe

using wrong log type in try-catch exception handle.

in org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer#doConvertMessage method used log.info instead of log.error in exception handling.

    private Object doConvertMessage(MessageExt messageExt) {
        if (Objects.equals(messageType, MessageExt.class) || Objects.equals(messageType, org.apache.rocketmq.common.message.Message.class)) {
            return messageExt;
        } else {
            String str = new String(messageExt.getBody(), Charset.forName(charset));
            if (Objects.equals(messageType, String.class)) {
                return str;
            } else {
                // If msgType not string, use objectMapper change it.
                try {
                   // ignored
                } catch (Exception e) {

                    // here it is 👇
                    log.info("convert failed. str:{}, msgType:{}", str, messageType);
                    throw new RuntimeException("cannot convert message to " + messageType, e);
                }
            }
        }
    }

log.info should print normal log, it shoud be using log.error instead of log.info

how to fix

    private Object doConvertMessage(MessageExt messageExt) {
        if (Objects.equals(messageType, MessageExt.class) || Objects.equals(messageType, org.apache.rocketmq.common.message.Message.class)) {
            return messageExt;
        } else {
            String str = new String(messageExt.getBody(), Charset.forName(charset));
            if (Objects.equals(messageType, String.class)) {
                return str;
            } else {
                // If msgType not string, use objectMapper change it.
                try {
                   // ignored
                } catch (Exception e) {

                    // change like this
                    log.error("convert failed. str:{}, msgType:{},\n convert error msg: {}.", str, messageType, e.getMessage());
                    throw new RuntimeException("cannot convert message to " + messageType, e);
                }
            }
        }
    }
Dominant language
Java
Stars
2.3k
Forks
942
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/rocketmq-spring

All issues in apache/rocketmq-spring

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.