You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Michael Busch (JIRA)" <ji...@apache.org> on 2007/06/22 03:32:25 UTC
[jira] Created: (LUCENE-939) Check for boundary conditions in
FieldInfos
Check for boundary conditions in FieldInfos
-------------------------------------------
Key: LUCENE-939
URL: https://issues.apache.org/jira/browse/LUCENE-939
Project: Lucene - Java
Issue Type: Improvement
Reporter: Michael Busch
Assignee: Michael Busch
Priority: Trivial
Fix For: 2.3
In FieldInfos there are three methods in which we don't check for
boundary conditions but catch e. g. an IndexOutOfBoundsException
or a NPE. I think this isn't good code style and is probably not
even faster than checking explicitly.
"Exceptions should not be used to alter the flow of a program as
part of normal execution."
Also this can be irritating when you're trying to debug an
IndexOutOfBoundsException that is thrown somewhere else in your
program and you place a breakpoint on that exception.
The three methods are:
public int fieldNumber(String fieldName) {
try {
FieldInfo fi = fieldInfo(fieldName);
if (fi != null)
return fi.number;
}
catch (IndexOutOfBoundsException ioobe) {
return -1;
}
return -1;
}
public String fieldName(int fieldNumber) {
try {
return fieldInfo(fieldNumber).name;
}
catch (NullPointerException npe) {
return "";
}
}
public FieldInfo fieldInfo(int fieldNumber) {
try {
return (FieldInfo) byNumber.get(fieldNumber);
}
catch (IndexOutOfBoundsException ioobe) {
return null;
}
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org
[jira] Resolved: (LUCENE-939) Check for boundary conditions in
FieldInfos
Posted by "Michael Busch (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LUCENE-939?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Michael Busch resolved LUCENE-939.
----------------------------------
Resolution: Fixed
> Check for boundary conditions in FieldInfos
> -------------------------------------------
>
> Key: LUCENE-939
> URL: https://issues.apache.org/jira/browse/LUCENE-939
> Project: Lucene - Java
> Issue Type: Improvement
> Reporter: Michael Busch
> Assignee: Michael Busch
> Priority: Trivial
> Fix For: 2.3
>
> Attachments: lucene-939.patch
>
>
> In FieldInfos there are three methods in which we don't check for
> boundary conditions but catch e. g. an IndexOutOfBoundsException
> or a NPE. I think this isn't good code style and is probably not
> even faster than checking explicitly.
> "Exceptions should not be used to alter the flow of a program as
> part of normal execution."
> Also this can be irritating when you're trying to debug an
> IndexOutOfBoundsException that is thrown somewhere else in your
> program and you place a breakpoint on that exception.
> The three methods are:
> public int fieldNumber(String fieldName) {
> try {
> FieldInfo fi = fieldInfo(fieldName);
> if (fi != null)
> return fi.number;
> }
> catch (IndexOutOfBoundsException ioobe) {
> return -1;
> }
> return -1;
> }
>
> public String fieldName(int fieldNumber) {
> try {
> return fieldInfo(fieldNumber).name;
> }
> catch (NullPointerException npe) {
> return "";
> }
> }
>
>
> public FieldInfo fieldInfo(int fieldNumber) {
> try {
> return (FieldInfo) byNumber.get(fieldNumber);
> }
> catch (IndexOutOfBoundsException ioobe) {
> return null;
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org
[jira] Updated: (LUCENE-939) Check for boundary conditions in
FieldInfos
Posted by "Michael Busch (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LUCENE-939?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Michael Busch updated LUCENE-939:
---------------------------------
Attachment: lucene-939.patch
This patch removes the catch clauses and adds explicit checks
for the boundary cases.
In fieldInfo(int fieldNumber) we only have to check if
fieldNumber>=0 because of one special case: the very first
term in the dictionary is always an empty term "":"". That's
why -1 is stored as field number for this term in the
dictionary. If we could avoid storing the empty term then we
could also get rid of these checks in FieldInfos. When I
have some time I'll look into that and add a separate issue.
All tests pass with this patch.
> Check for boundary conditions in FieldInfos
> -------------------------------------------
>
> Key: LUCENE-939
> URL: https://issues.apache.org/jira/browse/LUCENE-939
> Project: Lucene - Java
> Issue Type: Improvement
> Reporter: Michael Busch
> Assignee: Michael Busch
> Priority: Trivial
> Fix For: 2.3
>
> Attachments: lucene-939.patch
>
>
> In FieldInfos there are three methods in which we don't check for
> boundary conditions but catch e. g. an IndexOutOfBoundsException
> or a NPE. I think this isn't good code style and is probably not
> even faster than checking explicitly.
> "Exceptions should not be used to alter the flow of a program as
> part of normal execution."
> Also this can be irritating when you're trying to debug an
> IndexOutOfBoundsException that is thrown somewhere else in your
> program and you place a breakpoint on that exception.
> The three methods are:
> public int fieldNumber(String fieldName) {
> try {
> FieldInfo fi = fieldInfo(fieldName);
> if (fi != null)
> return fi.number;
> }
> catch (IndexOutOfBoundsException ioobe) {
> return -1;
> }
> return -1;
> }
>
> public String fieldName(int fieldNumber) {
> try {
> return fieldInfo(fieldNumber).name;
> }
> catch (NullPointerException npe) {
> return "";
> }
> }
>
>
> public FieldInfo fieldInfo(int fieldNumber) {
> try {
> return (FieldInfo) byNumber.get(fieldNumber);
> }
> catch (IndexOutOfBoundsException ioobe) {
> return null;
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org