You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Leo Li (JIRA)" <ji...@apache.org> on 2007/03/13 02:49:09 UTC
[jira] Created: (HARMONY-3373)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception
mechanism as logic in write(int)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception mechanism as logic in write(int)
------------------------------------------------------------------------------------------------------
Key: HARMONY-3373
URL: https://issues.apache.org/jira/browse/HARMONY-3373
Project: Harmony
Issue Type: Improvement
Components: Classlib
Reporter: Leo Li
In ByteArrayOutputStream.write(int):
public synchronized void write(int oneByte) {
try {
buf[count] = (byte) oneByte;
count++;
} catch (IndexOutOfBoundsException e) {
// Expand when necessary
expand(1);
buf[count++] = (byte) oneByte;
} catch (NullPointerException e) {
}
}
Exception mechanism is adopted as a logic to judge whether current position is out of the boundary of the backing array. So, I recommend to use explicit condtion to judge it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-3373)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception
mechanism as logic in write(int)
Posted by "Leo Li (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-3373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12483358 ]
Leo Li commented on HARMONY-3373:
---------------------------------
Hi, Alexey:
Verified. Thank you.
Good luck!
Leo.
> [classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception mechanism as logic in write(int)
> ------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-3373
> URL: https://issues.apache.org/jira/browse/HARMONY-3373
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Leo Li
> Assigned To: Alexey Petrenko
> Attachments: patch-3373.diff
>
>
> In ByteArrayOutputStream.write(int):
> public synchronized void write(int oneByte) {
> try {
> buf[count] = (byte) oneByte;
> count++;
> } catch (IndexOutOfBoundsException e) {
> // Expand when necessary
> expand(1);
> buf[count++] = (byte) oneByte;
> } catch (NullPointerException e) {
> }
> }
> Exception mechanism is adopted as a logic to judge whether current position is out of the boundary of the backing array. So, I recommend to use explicit condtion to judge it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (HARMONY-3373)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception
mechanism as logic in write(int)
Posted by "Leo Li (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-3373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Leo Li updated HARMONY-3373:
----------------------------
Patch Info: [Patch Available]
> [classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception mechanism as logic in write(int)
> ------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-3373
> URL: https://issues.apache.org/jira/browse/HARMONY-3373
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Leo Li
> Attachments: patch-3373.diff
>
>
> In ByteArrayOutputStream.write(int):
> public synchronized void write(int oneByte) {
> try {
> buf[count] = (byte) oneByte;
> count++;
> } catch (IndexOutOfBoundsException e) {
> // Expand when necessary
> expand(1);
> buf[count++] = (byte) oneByte;
> } catch (NullPointerException e) {
> }
> }
> Exception mechanism is adopted as a logic to judge whether current position is out of the boundary of the backing array. So, I recommend to use explicit condtion to judge it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (HARMONY-3373)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception
mechanism as logic in write(int)
Posted by "Alexey Petrenko (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-3373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alexey Petrenko resolved HARMONY-3373.
--------------------------------------
Resolution: Fixed
Leo, thanks for the explanation.
The patch has been applied.
Please verify.
> [classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception mechanism as logic in write(int)
> ------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-3373
> URL: https://issues.apache.org/jira/browse/HARMONY-3373
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Leo Li
> Assigned To: Alexey Petrenko
> Attachments: patch-3373.diff
>
>
> In ByteArrayOutputStream.write(int):
> public synchronized void write(int oneByte) {
> try {
> buf[count] = (byte) oneByte;
> count++;
> } catch (IndexOutOfBoundsException e) {
> // Expand when necessary
> expand(1);
> buf[count++] = (byte) oneByte;
> } catch (NullPointerException e) {
> }
> }
> Exception mechanism is adopted as a logic to judge whether current position is out of the boundary of the backing array. So, I recommend to use explicit condtion to judge it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-3373)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception
mechanism as logic in write(int)
Posted by "Alexey Petrenko (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-3373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12482406 ]
Alexey Petrenko commented on HARMONY-3373:
------------------------------------------
Leo,
thanks for catching this up. This piece of code really need to be rewritten.
But you code is not equal to the original one since you removed (buf == null) handling.
So I suggest something like
if (buff != null) {
if (count == buf.length) {
expand(1);
}
buf[count++] = (byte) oneByte;
}
Or (buf == null) is impossible case?
What do you think?
> [classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception mechanism as logic in write(int)
> ------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-3373
> URL: https://issues.apache.org/jira/browse/HARMONY-3373
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Leo Li
> Assigned To: Alexey Petrenko
> Attachments: patch-3373.diff
>
>
> In ByteArrayOutputStream.write(int):
> public synchronized void write(int oneByte) {
> try {
> buf[count] = (byte) oneByte;
> count++;
> } catch (IndexOutOfBoundsException e) {
> // Expand when necessary
> expand(1);
> buf[count++] = (byte) oneByte;
> } catch (NullPointerException e) {
> }
> }
> Exception mechanism is adopted as a logic to judge whether current position is out of the boundary of the backing array. So, I recommend to use explicit condtion to judge it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (HARMONY-3373)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception
mechanism as logic in write(int)
Posted by "Leo Li (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-3373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Leo Li updated HARMONY-3373:
----------------------------
Attachment: patch-3373.diff
Will somebody try the patch?
> [classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception mechanism as logic in write(int)
> ------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-3373
> URL: https://issues.apache.org/jira/browse/HARMONY-3373
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Leo Li
> Attachments: patch-3373.diff
>
>
> In ByteArrayOutputStream.write(int):
> public synchronized void write(int oneByte) {
> try {
> buf[count] = (byte) oneByte;
> count++;
> } catch (IndexOutOfBoundsException e) {
> // Expand when necessary
> expand(1);
> buf[count++] = (byte) oneByte;
> } catch (NullPointerException e) {
> }
> }
> Exception mechanism is adopted as a logic to judge whether current position is out of the boundary of the backing array. So, I recommend to use explicit condtion to judge it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Closed: (HARMONY-3373)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception
mechanism as logic in write(int)
Posted by "Alexey Petrenko (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-3373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alexey Petrenko closed HARMONY-3373.
------------------------------------
> [classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception mechanism as logic in write(int)
> ------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-3373
> URL: https://issues.apache.org/jira/browse/HARMONY-3373
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Leo Li
> Assigned To: Alexey Petrenko
> Attachments: patch-3373.diff
>
>
> In ByteArrayOutputStream.write(int):
> public synchronized void write(int oneByte) {
> try {
> buf[count] = (byte) oneByte;
> count++;
> } catch (IndexOutOfBoundsException e) {
> // Expand when necessary
> expand(1);
> buf[count++] = (byte) oneByte;
> } catch (NullPointerException e) {
> }
> }
> Exception mechanism is adopted as a logic to judge whether current position is out of the boundary of the backing array. So, I recommend to use explicit condtion to judge it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Assigned: (HARMONY-3373)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception
mechanism as logic in write(int)
Posted by "Alexey Petrenko (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-3373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alexey Petrenko reassigned HARMONY-3373:
----------------------------------------
Assignee: Alexey Petrenko
> [classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception mechanism as logic in write(int)
> ------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-3373
> URL: https://issues.apache.org/jira/browse/HARMONY-3373
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Leo Li
> Assigned To: Alexey Petrenko
> Attachments: patch-3373.diff
>
>
> In ByteArrayOutputStream.write(int):
> public synchronized void write(int oneByte) {
> try {
> buf[count] = (byte) oneByte;
> count++;
> } catch (IndexOutOfBoundsException e) {
> // Expand when necessary
> expand(1);
> buf[count++] = (byte) oneByte;
> } catch (NullPointerException e) {
> }
> }
> Exception mechanism is adopted as a logic to judge whether current position is out of the boundary of the backing array. So, I recommend to use explicit condtion to judge it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (HARMONY-3373)
[classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception
mechanism as logic in write(int)
Posted by "Leo Li (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HARMONY-3373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12482988 ]
Leo Li commented on HARMONY-3373:
---------------------------------
Hi, Alexey:
Thank you for pointing out that.
The refractor I made is different from the original one. But buf should not be null in ByteArrayOutputStream after it has been initialized. And if we make a child class of it and let but to be null, RI will still throw NullPointerException when write(int) is invoked.
Good luck,
Leo.
> [classlib][luni]java.io.ByteArrayOutputStream: avoid to use exception mechanism as logic in write(int)
> ------------------------------------------------------------------------------------------------------
>
> Key: HARMONY-3373
> URL: https://issues.apache.org/jira/browse/HARMONY-3373
> Project: Harmony
> Issue Type: Improvement
> Components: Classlib
> Reporter: Leo Li
> Assigned To: Alexey Petrenko
> Attachments: patch-3373.diff
>
>
> In ByteArrayOutputStream.write(int):
> public synchronized void write(int oneByte) {
> try {
> buf[count] = (byte) oneByte;
> count++;
> } catch (IndexOutOfBoundsException e) {
> // Expand when necessary
> expand(1);
> buf[count++] = (byte) oneByte;
> } catch (NullPointerException e) {
> }
> }
> Exception mechanism is adopted as a logic to judge whether current position is out of the boundary of the backing array. So, I recommend to use explicit condtion to judge it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.