[jira] [Updated] (EMAIL-205) Possible Dead Code in EmailUtils.encodeURL()?
[ https://issues.apache.org/jira/browse/EMAIL-205?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Adam Emerson updated EMAIL-205: --- 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: {code:java} for (final byte c : input.getBytes(US_ASCII)) { int b = c; if (b < 0) { b = 256 + b; } ...{code} 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! was: 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: {code:java} for (final byte c : input.getBytes(US_ASCII)) { int b = c; if (b < 0) { b = 256 + b; } ...{code} 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! > Possible Dead Code in EmailUtils.encodeURL()? > - > > Key: EMAIL-205 > URL: https://issues.apache.org/jira/browse/EMAIL-205 > Project: Commons Email > Issue Type: Improvement >Reporter: Adam Emerson >Priority: Minor > > 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: > {code:java} > for (final byte c : input.getBytes(US_ASCII)) > { > int b = c; > if (b < 0) > { > b = 256 + b; > } > ...{code} > 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! > -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Updated] (EMAIL-205) Possible Dead Code in EmailUtils.encodeURL()?
[ https://issues.apache.org/jira/browse/EMAIL-205?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Adam Emerson updated EMAIL-205: --- 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: {code:java} for (final byte c : input.getBytes(US_ASCII)) { int b = c; if (b < 0) { b = 256 + b; } ...{code} 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! was: 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: {code:java} for (final byte c : input.getBytes(US_ASCII)) { int b = c; if (b < 0) { b = 256 + b; } ...{code} 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! > Possible Dead Code in EmailUtils.encodeURL()? > - > > Key: EMAIL-205 > URL: https://issues.apache.org/jira/browse/EMAIL-205 > Project: Commons Email > Issue Type: Improvement >Reporter: Adam Emerson >Priority: Minor > > 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: > {code:java} > for (final byte c : input.getBytes(US_ASCII)) > { > int b = c; > if (b < 0) > { > b = 256 + b; > } > ...{code} > 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! > -- This message was sent by Atlassian Jira (v8.20.10#820010)
[jira] [Created] (EMAIL-205) Possible Dead Code in EmailUtils.encodeURL()?
Adam Emerson created EMAIL-205: -- Summary: Possible Dead Code in EmailUtils.encodeURL()? Key: EMAIL-205 URL: https://issues.apache.org/jira/browse/EMAIL-205 Project: Commons Email Issue Type: Improvement Reporter: Adam Emerson 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: {code:java} for (final byte c : input.getBytes(US_ASCII)) { int b = c; if (b < 0) { b = 256 + b; } ...{code} 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! -- This message was sent by Atlassian Jira (v8.20.10#820010)