Uploaded image for project: 'Commons Email'
  1. Commons Email
  2. EMAIL-205

Possible Dead Code in EmailUtils.encodeURL()?

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 1.6.0
    • None

    Description

      Hello,

      I was doing some testing on the library for a university project and came across what may be some dead code in the EmailUtils.encodeURL() function.

      The code in question is the if block at line 298:

      for (final byte c : input.getBytes(US_ASCII))
      {
          int b = c;
          if (b < 0)
          {
              b = 256 + b;
          }
      ...

      I realize that the

      b = 256 + b;

      condition is there as an attempt to handle the fact that bytes are signed in Java, however, when I look at the implementation of

      input.getBytes(US_ASCII),

      I don't see any case that it can return a negative byte value.  getBytes(US_ASCII) returns a '?' character for any non-ascii character, thus preventing an overflow that may result in a negative byte ('?' has a value of 63).  This would mean that the the contents of the if statement are unreachable.

      If anyone with more experience has the time to take a look at this I would greatly appreciate it. For my own education, I would love to see a test case in which a negative byte value would be returned here.

      Thanks!

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              adamgemerson Adam Emerson
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: