开发者

ArrayList creation: (some object) cannot be stored in an array of type java.lang.Object[]

开发者 https://www.devze.com 2023-04-04 17:15 出处:网络
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[].

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开发者_C百科 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消