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

java.net.URI.scanIPv4Address throws unnecessary URISyntaxException

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 25
    • None
    • core-libs
    • b14

      ```
              private int scanIPv4Address(int start, int n, boolean strict)
                  throws URISyntaxException
              {
                  int p = start;
                  int q;
                  int m = scan(p, n, L_DIGIT | L_DOT, H_DIGIT | H_DOT);
                  if ((m <= p) || (strict && (m != n)))
                      return -1;
                  for (;;) {
                      // Per RFC2732: At most three digits per byte
                      // Further constraint: Each element fits in a byte
                      if ((q = scanByte(p, m)) <= p) break; p = q;
                      if ((q = scan(p, m, '.')) <= p) break; p = q;
                      if ((q = scanByte(p, m)) <= p) break; p = q;
                      if ((q = scan(p, m, '.')) <= p) break; p = q;
                      if ((q = scanByte(p, m)) <= p) break; p = q;
                      if ((q = scan(p, m, '.')) <= p) break; p = q;
                      if ((q = scanByte(p, m)) <= p) break; p = q;
                      if (q < m) break;
                      return q;
                  }
                  fail("Malformed IPv4 address", q);
                  return -1;
              }
      ```

      Looking into cpu profile data of one of our system, noticed the URISyntaxException threw at fail("Malformed IPv4 address", q) used about 0.3% CPU, we could add `-XX:+OmitStackTraceInFastThrow`, but after further looking into URI code, we think it should be fixed in JDK.

            xpeng Xiaolong Peng
            xpeng Xiaolong Peng
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: