Author: cstamas
Date: Mon Dec 13 14:40:57 2010
New Revision: 1045146

URL: http://svn.apache.org/viewvc?rev=1045146&view=rev
Log:
Should not leak lucene specific exceptions, wrong query inputs not returns 
IllegalArgumentExceptions.

Modified:
    
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
    
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java
    
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java
    
maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java

Modified: 
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
URL: 
http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java?rev=1045146&r1=1045145&r2=1045146&view=diff
==============================================================================
--- 
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
 (original)
+++ 
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/DefaultNexusIndexer.java
 Mon Dec 13 14:40:57 2010
@@ -433,9 +433,16 @@ public class DefaultNexusIndexer
     // 
----------------------------------------------------------------------------
 
     public Query constructQuery( Field field, String query, SearchType type )
-        throws ParseException
+        throws IllegalArgumentException
     {
-        return queryCreator.constructQuery( field, query, type );
+        try
+        {
+            return queryCreator.constructQuery( field, query, type );
+        }
+        catch ( ParseException e )
+        {
+            throw new IllegalArgumentException( e );
+        }
     }
 
     // 
----------------------------------------------------------------------------
@@ -443,7 +450,7 @@ public class DefaultNexusIndexer
     // 
----------------------------------------------------------------------------
 
     public ArtifactInfo identify( Field field, String query )
-        throws ParseException, IOException
+        throws IllegalArgumentException, IOException
     {
         return identify( constructQuery( field, query, SearchType.EXACT ) );
     }
@@ -484,11 +491,6 @@ public class DefaultNexusIndexer
         {
             throw new IOException( "Unable to calculate digest" );
         }
-        catch ( ParseException e )
-        {
-            // will not happen
-            return null;
-        }
         finally
         {
             IOUtil.close( is );

Modified: 
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java
URL: 
http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java?rev=1045146&r1=1045145&r2=1045146&view=diff
==============================================================================
--- 
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java
 (original)
+++ 
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/NexusIndexer.java
 Mon Dec 13 14:40:57 2010
@@ -24,7 +24,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.store.Directory;
 import org.apache.maven.index.cli.NexusIndexerCli;
@@ -313,7 +312,7 @@ public interface NexusIndexer
      * @return
      */
     Query constructQuery( Field field, String query, SearchType type )
-        throws ParseException;
+        throws IllegalArgumentException;
 
     // throws ParseException;
 
@@ -322,7 +321,7 @@ public interface NexusIndexer
     // 
----------------------------------------------------------------------------
 
     ArtifactInfo identify( Field field, String query )
-        throws ParseException, IOException;
+        throws IllegalArgumentException, IOException;
 
     ArtifactInfo identify( File artifact )
         throws IOException;

Modified: 
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java
URL: 
http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java?rev=1045146&r1=1045145&r2=1045146&view=diff
==============================================================================
--- 
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java
 (original)
+++ 
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/treeview/DefaultIndexTreeView.java
 Mon Dec 13 14:40:57 2010
@@ -24,7 +24,6 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.Query;
@@ -498,37 +497,16 @@ public class DefaultIndexTreeView
         Query versionQ = null;
 
         // minimum must have
-        try
-        {
-            groupIdQ = getNexusIndexer().constructQuery( MAVEN.GROUP_ID, g, 
SearchType.EXACT );
-        }
-        catch ( ParseException e )
-        {
-            // will not happen
-        }
+        groupIdQ = getNexusIndexer().constructQuery( MAVEN.GROUP_ID, g, 
SearchType.EXACT );
 
         if ( StringUtils.isNotBlank( a ) )
         {
-            try
-            {
-                artifactIdQ = getNexusIndexer().constructQuery( 
MAVEN.ARTIFACT_ID, a, SearchType.EXACT );
-            }
-            catch ( ParseException e )
-            {
-                // will not happen
-            }
+            artifactIdQ = getNexusIndexer().constructQuery( MAVEN.ARTIFACT_ID, 
a, SearchType.EXACT );
         }
 
         if ( StringUtils.isNotBlank( v ) )
         {
-            try
-            {
-                versionQ = getNexusIndexer().constructQuery( MAVEN.VERSION, v, 
SearchType.EXACT );
-            }
-            catch ( ParseException e )
-            {
-                // will not happen
-            }
+            versionQ = getNexusIndexer().constructQuery( MAVEN.VERSION, v, 
SearchType.EXACT );
         }
 
         BooleanQuery q = new BooleanQuery();

Modified: 
maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
URL: 
http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java?rev=1045146&r1=1045145&r2=1045146&view=diff
==============================================================================
--- 
maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
 (original)
+++ 
maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
 Mon Dec 13 14:40:57 2010
@@ -28,7 +28,6 @@ import java.util.Set;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.search.Query;
 import org.apache.maven.index.search.grouping.GAGrouping;
 
@@ -184,7 +183,7 @@ public abstract class AbstractRepoNexusI
 
                 fail( "Input is invalid, query cannot start with *!" );
             }
-            catch ( ParseException e )
+            catch ( IllegalArgumentException e )
             {
                 // good, now let's do it again with good input:
                 q = nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, "logging", 
SearchType.SCORED );
@@ -216,7 +215,7 @@ public abstract class AbstractRepoNexusI
 
                 fail( "Input is invalid, query cannot start with *!" );
             }
-            catch ( ParseException e )
+            catch ( IllegalArgumentException e )
             {
                 // good, now let's do it again with good input:
                 // Note: since queries are really parsed now, the leading "-" 
is wrong too
@@ -266,7 +265,7 @@ public abstract class AbstractRepoNexusI
 
                 fail( "Input is invalid, query cannot start with *!" );
             }
-            catch ( ParseException e )
+            catch ( IllegalArgumentException e )
             {
                 // good, now let's do it again with good input:
                 // NOTE: without crappy prefix search (that caused zillion 
other problems, original input does not work)
@@ -334,7 +333,7 @@ public abstract class AbstractRepoNexusI
 
                 fail( "Input is invalid, query cannot start with *!" );
             }
-            catch ( ParseException e )
+            catch ( IllegalArgumentException e )
             {
                 // good, now let's do it again with good input:
                 q = nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, "slf4*", 
SearchType.SCORED );


Reply via email to