0

This simple line of code is giving me a headache :

Set<Long> statutList = rechercheSalarieForm.getIdStatutList();

getIdStatutList() is returning a set of Longs

BUT when I do :

statutList.toArray()[0].getClass() 

or

rechercheSalarieForm.getIdStatutList().toArray()[0].getClass()

The result is :

(java.lang.Class<T>) class java.lang.String

This statutList is send straight to DAO layer which doesn't like Strings in the hibernate request.

How is it possible to have Strings in a Long array ?

Edit :

Short program :

public List<EffectifRupHistoriqueExtractionVO>   
generateExtractionRupHistorique(RechercheSalariesRupFormVO rechercheSalarieForm) throws       FunctionalException {

    Collection<Long> statutList = rechercheSalarieForm.getIdStatutList();
    // Some business/Dao call with statutList in parameter
}

Object RechercheSalariesRupFormVO :

public class RechercheSalariesRupFormVO extends ValueObject{
// some declaration
    private Set<Long> idStatutList;
    public Set<Long> getIdStatutList() {
        return idStatutList;
    }
}
eclips
  • 15
  • 5
  • 3
    Can you reproduce this in a short but complete program? What is the *actual* type used by `getIdStatutList`? – Jon Skeet Mar 26 '14 at 09:48
  • 1
    The only possilbity is that getIdStatutList() returns unchecked types and you are converting that in to Set. You will see warning in such scenario. – Amit Deshpande Mar 26 '14 at 09:54
  • Check the class of an element of `idStatutList` before returning it (in `getIdStatutList()`). To see whether it 1) has indeed the correct values and 2) that you are actually calling that method and not some other (similar) one. – Veger Mar 26 '14 at 10:04
  • 1
    We need to see a **complete** program. The code you posted is by no means complete. We can't run it and it will not reproduce this. – Radiodef Mar 26 '14 at 10:36
  • @Jon Skeet : i can't produce a "short" program, there is 4 layers involved. The IHM layer sending RechercheSalariesRupFormVO is in Flex – eclips Mar 26 '14 at 11:31
  • Just because there are 4 layers involved in the *real* code doesn't mean that there have to be 4 layers involved to reproduce the problem. Part of your job in diagnosing the issue is to isolate it as far as possible. – Jon Skeet Mar 26 '14 at 11:32
  • @Veger idStatutlist from rechercheSalarieForm is a java.lang.Object. – eclips Mar 26 '14 at 11:34

1 Answers1

0

Here is a work arround (it's ugly) :

int size = rechercheSalarieForm.getIdStatutList().size();
Collection<Long> statutList = new ArrayList<Long>();
int i=0;
for (i = 0; i < size ; i++) {               
    statutList.add(Long.valueOf(rechercheSalarieForm.getIdStatutList().toArray()[i].toString()));
}

Thanks to him : https://stackoverflow.com/a/12881094/2369897

if anyone know the why ...

Community
  • 1
  • 1
eclips
  • 15
  • 5