Uploaded image for project: 'Apache RocketMQ'
  1. Apache RocketMQ
  2. ROCKETMQ-206

Load JSON config file error if non-1byte character exists

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.0.0-incubating
    • Fix Version/s: 4.1.0-incubating
    • Component/s: rocketmq-commons
    • Labels:
      None

      Description

      If there are some non-1byte character in consumeroffset.json or other config files, when Broker restarted, the file contents will be ignored.

      See this method, when file.length() != character number, bug triggered.

      public static String file2String(final File file) {
              if (file.exists()) {
                  char[] data = new char[(int) file.length()];
                  boolean result = false;
      
                  FileReader fileReader = null;
                  try {
                      fileReader = new FileReader(file);
                      int len = fileReader.read(data);
                      result = len == data.length;
                  } catch (IOException e) {
                      // e.printStackTrace();
                  } finally {
                      if (fileReader != null) {
                          try {
                              fileReader.close();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      }
                  }
      
                  if (result) {
                      return new String(data);
                  }
              }
              return null;
          }
      

        Attachments

          Activity

            People

            • Assignee:
              Yukon yukon
              Reporter:
              Yukon yukon
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: