I have code of javabridge but when I want to rebuild this code, I got an error in this code: code witch call the code error is here
private <T> SoftReference getReference(final URLClassLoaderEntry entry, final List handlers) {
if (handlers.isEmpty()) {
return new SoftReference((T)entry);
}
return new DeleteTempFileAction(entry, DynamicClassLoader.TEMP_FILE_QUEUE, handlers);
}
here the code where i got error
public DeleteTempFileAction(final Object arg0, final ReferenceQueue arg1, final List handlers) {
super(arg0, arg1);
this.handlers = handlers;
DynamicClassLoader.DELETE_TEMP_FILE_ACTIONS.add(this);
if (Logger.getLogLevel() > 4) {
int count = 0;
int orphaned = 0;
for (final SoftReference val : DynamicClassLoader.DELETE_TEMP_FILE_ACTIONS) {
++count;
if (val.get() == null) {
++orphaned;
}
}
Logger.logDebug("classloader stats: entries: " + count + " orphaned: " + orphaned);
}
}
public void command() {
for (final DynamicHttpURLConnectionHandler handler : this.handlers) {
handler.deleteTempFile();
}
}
At this code I got 2 error there are in: 1.
for (final SoftReference val : DynamicClassLoader.DELETE_TEMP_FILE_ACTIONS) {
++count;
if (val.get() == null) {
++orphaned;
}
}
for (final DynamicHttpURLConnectionHandler handler : this.handlers) { handler.deleteTempFile(); }
Error for the first code is:
Type Missmatch : Cannot convert from element type object to SoftReference
Error for the second code is:
Type Missmatch : Cannot convert from element type object to DynamicHttpURLConnectionHandler
type of DynamicClassLoader.DELETE_TEMP_FILE_ACTIONS is
private static final Set DELETE_TEMP_FILE_ACTIONS;
and for the second one for class of DynamicHttpURLConnectionHandler is
class DynamicHttpURLConnectionHandler extends URLStreamHandler
{
private JarFile jarFile;
private File baseFile;
private Map headerFields;
public DynamicHttpURLConnectionHandler() {
if (Logger.getLogLevel() > 4) {
Logger.logDebug("tempfile create DynamicHttpURLConnectionHander " + this);
}
}
@Override
protected URLConnection openConnection(final URL u) throws IOException {
return new DynamicJarURLConnection(u, this);
}
public void deleteTempFile() {
if (Logger.getLogLevel() > 4) {
Logger.logDebug("classloader tempfile deleted: " + this.baseFile + " handler: " + this);
}
this.baseFile.delete();
}
public Map getHeaderFields() {
return this.headerFields;
}
public JarFile getTempFile() {
return this.jarFile;
}
public void setTempFile(final JarFile jarFile, final File baseFile) {
if (Logger.getLogLevel() > 4) {
Logger.logDebug("classloader tempfile created: " + baseFile + " handler" + this);
}
this.jarFile = jarFile;
this.baseFile = baseFile;
}
public void setHeaderFields(final Map headerFields) {
this.headerFields = headerFields;
}
}
for SoftReference I have this class
public class SoftReference extends Reference {
/**
* Timestamp clock, updated by the garbage collector
*/
static private long clock;
/**
* Timestamp updated by each invocation of the get method. The VM may use
* this field when selecting soft references to be cleared, but it is not
* required to do so.
*/
private long timestamp;
/**
* Creates a new soft reference that refers to the given object. The new
* reference is not registered with any queue.
*
* @param referent object the new soft reference will refer to
*/
public SoftReference(T referent) {
super(referent);
this.timestamp = clock;
}
/**
* Creates a new soft reference that refers to the given object and is
* registered with the given queue.
*
* @param referent object the new soft reference will refer to
* @param q the queue with which the reference is to be registered,
* or <tt>null</tt> if registration is not required
*
*/
public SoftReference(T referent, ReferenceQueue<? super T> q) {
super(referent, q);
this.timestamp = clock;
}
/**
* Returns this reference object's referent. If this reference object has
* been cleared, either by the program or by the garbage collector, then
* this method returns <code>null</code>.
*
* @return The object to which this reference refers, or
* <code>null</code> if this reference object has been cleared
*/
public T get() {
T o = super.get();
if (o != null && this.timestamp != clock)
this.timestamp = clock;
return o;
}
}
i have try to use Set but still got an error
My question is how to fix this problem?