3

Usually, the code block works perfect. On very rare occasions though, the "new ArrayList" throws an Exeption my.namespace.CacheEntry cannot be stored in an array of type java.lang.Object[].

Checking Google, someone else seemed to get this exception on an Acer A500 with 3.1 (which is the device I got it, too). I don't see any hit for this in generic Java or whatever, so may be some very very Honeycomb special case or even a VM bug?

private long expireCache(HashMap<String, CacheEntry> map) {
    long count = 0;
    // next line will sometimes throw the exception:
    ArrayList<CacheEntry> entries = new ArrayList<CacheEntry>(map.values());
    Collections.sort(entries);

The CacheEntry class is quite regular, too:

final class CacheEntry implements Comparable<CacheEntry> {
    public File file;
    public Long time;

    CacheEntry(File cacheFile) {
        // retreive the lastModified only once, don't do heavy I/O for sorting,
        // keep it desynced from filesystem so nothing bad happens when the 
        // file gets changed while sorting:
        file = cacheFile;
        time = cacheFile.lastModified();
        }

     // "touch" the cached last modified time
     public void touch() {
        time = System.currentTimeMillis();
        }

     // return the long comparable of last modified time
     public int compareTo(CacheEntry c) {
        return time.compareTo(c.time);
        }
     }

I don't see anything wrong with this code. Anyone?

3
  • Where and how do you invoke expireCache? Give example please. Commented Sep 13, 2011 at 10:58
  • Your code seems correct, it looks like a Honeycomb bug indeed. Commented Sep 13, 2011 at 10:59
  • @Alexandr, I think it totally doesn't matter for this problem when and how this function gets called. But if you really need to know, it gets called from inside a syncronized(cacheentry-hashmap) entry (as all changes to the hashmap are inside synchronized), when the size of the cache or the number of elements in the map are over a highwater mark. Commented Sep 13, 2011 at 11:12

1 Answer 1

2

may be some very very Honeycomb special case or even a VM bug?

Yes, looks like it, because according to Java semantics, there isn't anything that "cannot be stored in an array of type java.lang.Object[]" - except primitives, but those can't be values in a HashMap

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.