You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Henno Vermeulen <he...@huizemolenaar.nl> on 2011/08/23 15:28:43 UTC

illogical java.lang.IllegalArgumentException: Input parameter "ids" is empty

I have a query that goes like "SELECT e.id, ... FROM ... WHERE e.id IN :ids". Parameter ids is a list of ids. When it is empty and I execute the query, OpenJPA throws java.lang.IllegalArgumentException: Input parameter "ids" is empty.

Why not just return an empty list? I feel this is much like iterating over an empty Collection: by not throwing an exception you get less complex code than when you have to write an if statement to handle empty collections.

Regards,
Henno Vermeulen
Huize Molenaar

RE: illogical java.lang.IllegalArgumentException: Input parameter "ids" is empty

Posted by Henno Vermeulen <he...@huizemolenaar.nl>.
Ok that sounds logical, I tried writing a sql server query "SELECT * FROM MyTable WHERE ID IN ()" and indeed this isn't correct SQL. However "SELECT * FROM MyTable WHERE ID IN (null)" works, but this is different from an empty list.

-----Oorspronkelijk bericht-----
Van: Boblitz John [mailto:John.Boblitz@BERTSCHI.com] 
Verzonden: dinsdag 23 augustus 2011 17:44
Aan: 'users@openjpa.apache.org'
Onderwerp: AW: illogical java.lang.IllegalArgumentException: Input parameter "ids" is empty

> -----Ursprüngliche Nachricht-----
> Von: Henno Vermeulen [mailto:henno@huizemolenaar.nl] 
> Gesendet: Dienstag, 23. August 2011 15:29
> An: 'users@openjpa.apache.org'
> Betreff: illogical java.lang.IllegalArgumentException: Input 
> parameter "ids" is empty
> 
> I have a query that goes like "SELECT e.id, ... FROM ... 
> WHERE e.id IN :ids". Parameter ids is a list of ids. When it 
> is empty and I execute the query, OpenJPA throws 
> java.lang.IllegalArgumentException: Input parameter "ids" is empty.
> 
> Why not just return an empty list? I feel this is much like 
> iterating over an empty Collection: by not throwing an 
> exception you get less complex code than when you have to 
> write an if statement to handle empty collections.
> 
> Regards,
> Henno Vermeulen
> Huize Molenaar
> 

Hello,

I would think it has a lot to do with the fact that the underlying
SQL cant be executed!  The SQL IN clause requires a list of values 
and if they are not provided, SQL will throw the error.

Further, an empty list is indicative of a query which found no entries
satisfying a given criteria (and implicitly, that the criteria were valid.)

The exception indicates that the criteria itself are invalid.

Anyway, just my 2 pence ...

 

John

---- 

Who is General Failure, and why is he reading my hard disk?



AW: illogical java.lang.IllegalArgumentException: Input parameter "ids" is empty

Posted by Boblitz John <Jo...@BERTSCHI.com>.
> -----Ursprüngliche Nachricht-----
> Von: Henno Vermeulen [mailto:henno@huizemolenaar.nl] 
> Gesendet: Dienstag, 23. August 2011 15:29
> An: 'users@openjpa.apache.org'
> Betreff: illogical java.lang.IllegalArgumentException: Input 
> parameter "ids" is empty
> 
> I have a query that goes like "SELECT e.id, ... FROM ... 
> WHERE e.id IN :ids". Parameter ids is a list of ids. When it 
> is empty and I execute the query, OpenJPA throws 
> java.lang.IllegalArgumentException: Input parameter "ids" is empty.
> 
> Why not just return an empty list? I feel this is much like 
> iterating over an empty Collection: by not throwing an 
> exception you get less complex code than when you have to 
> write an if statement to handle empty collections.
> 
> Regards,
> Henno Vermeulen
> Huize Molenaar
> 

Hello,

I would think it has a lot to do with the fact that the underlying
SQL cant be executed!  The SQL IN clause requires a list of values 
and if they are not provided, SQL will throw the error.

Further, an empty list is indicative of a query which found no entries
satisfying a given criteria (and implicitly, that the criteria were valid.)

The exception indicates that the criteria itself are invalid.

Anyway, just my 2 pence ...

 

John

---- 

Who is General Failure, and why is he reading my hard disk?


Re: illogical java.lang.IllegalArgumentException: Input parameter "ids" is empty

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
  On trunk version, JPQL query accepts empty list for IN parameter.
  Following pass:
	public void testEmptyInExpression() {
		String jpql = "select o from Book o where o.ISBN in (:ids)";
		List<String> ids = new ArrayList<String>();
		assertTrue(_em.createQuery(jpql).setParameter("ids",
ids).getResultList().isEmpty());
	}

  For further investigation, please post
  1. The query string
  2. Exact way of setting the IN parameter values
  3. Error stack


-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/illogical-java-lang-IllegalArgumentException-Input-parameter-ids-is-empty-tp6716202p6717297.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.