Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8364515

String.replaceAll bug

XMLWordPrintable

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      PID: 42676
      Host: localhost
      Main class: ReadFilesInfo-1.0-SNAPSHOT.jar
      Arguments: <none>

      JVM: Java HotSpot(TM) 64-Bit Server VM (25.211-b12, mixed mode)
      Java: version 1.8.0_211, vendor Oracle Corporation
      Java Home: C:\Program Files\Java\jdk1.8.0_211\jre
      JVM Flags: <none>

      A DESCRIPTION OF THE PROBLEM :
      Swing Frame using nio read spring jstack file(from linux)using String.replaceAll get not expected result.

      code part

                  // get nid
                  Matcher nidMatcher = Pattern.compile("nid=([^\\s,]+)").matcher(line);
                  if (nidMatcher.find()) {
                      dto.setNid(nidMatcher.group(1));
                  }
                          String statePre = line.replaceAll(".*" + dto.getNid(), "");
                          System.out.println("111 "+statePre);
                          if (Objects.nonNull(dto.getStackPointer())){
                              String stateSecond = statePre.replaceAll(dto.getStackPointer(), "");
                              System.out.println("222 " + stateSecond);
                              String state = stateSecond.replace("\\[\\]", "");
                              System.out.println("333 " + state);
                              dto.setState(state);
                          } else {
                              dto.setState(statePre);
                          }
                          System.out.println(line);


      console print part


      111 runnable [0x00007f18be0da000]
      222 runnl []
      333 runnl []
      "grpc-nio-worker-ELG-1-4" #90 daemon prio=5 os_prio=0 cpu=71631.36ms elapsed=1309289.32s tid=0x00007f18ac0de800 nid=0x2aa5d9 runnable [0x00007f18be0da000]

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run an spring boot app in linux
      jstack -l <pid> > stack.txt

      in windows write swing app using nio read file

              try (BufferedReader br = Files.newBufferedReader(file)) {
                  br.lines().forEach(line -> {
                      if (line.matches(BusinessConstants.THREAD_NAME_INFO_REGEX)) {
                          threadInfo(line, countMap, jStackThreadLineDTOS);
                      }
                  });
              } catch (IOException e) {
                  throw new RuntimeException(e);
              }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
       waiting on condition []
       runnable []
      ACTUAL -
       runnl []
       witing on onition []

            asajeev Anjana Sajeev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: