I have one thread continuously adding objects to an ArrayList and periodically clearing it with ArrayList.clear()
Another thread first clones it with ArrayList.clone() and then works with what is in it
sometimes this gives NullPointerException and says the ArrayList which should have been cloned is null.
Is this because it is being cloned at the time as it is being cleared? It can’t be that it happens just because another thread is adding objects to the list because that is happening at very high speeds and the nullpointerexpection happens rarely.
thanks.
i am thinking of synchronizing it but would rather not do it and try-catch it