Eclipse different behaviour for “Unchecked” warning due to “Potential heap pollution via varargs parameter”. How to fix?

喜你入骨 提交于 2019-12-02 15:29:12

问题


I have a simple Entry object for populating a list

public class Entry {
    //fields

    public Entry(int a, String b, String c) {
        //...
    }

    //some getters
}

and an AsyncTask that retrieves the entries.
On its onProgressUpdate...

                                               (here)
                                                 |
@Override                                        V
protected void onProgressUpdate(List<Entry>... param) {
    for (Entry e : param[0]) myAdapter.add(e);

    progressBar.incrementProgressBy(1);
    myAdapter.notifyDataSetChanged();
}

I have the warning:

Type safety: Potential heap pollution via varargs parameter param

This happens on a PC Linux 64bit while the opposite warning is shown on a notebook with the same version of Eclipse, same android project, same Linux Mint 16, just a 32bit OS, stating something as "remove this unnecessary annotation" (sorry if this is not the precise warning, I'm on the desktop PC now).

So basically I add and remove back and forth the annotation, switching between the two machines. I think this may be related, obviously, to the Java compiler in use or some other workspace setting.

Now, I'm not asking what actually is that setting/environment difference, but my question is if there is something that I can do in the code to fix this issue and remove the origin of the warning itself. I've read about the origin of this warning and what "heap pollution" means here, but no source gives a hint on a possible fix (i.e. here or here)

Edit:
I noticed that another @SuppressWarnings("unchecked") sits on doInBackground, where I call

List<Entry> list;
//inside a for statement:
    publishProgress(list);
//repeated N times

that gives this warning:

Type safety: A generic array of List is created for a varargs parameter

来源:https://stackoverflow.com/questions/23443493/eclipse-different-behaviour-for-unchecked-warning-due-to-potential-heap-pollu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!