Skip to content

Commit

Permalink
Cleanup raw type warnings related to WeakReference. (apache#3923)
Browse files Browse the repository at this point in the history
Cleanup raw type warnings related to WeakReference. for issues like this..

[repeat] /home/bwalker/src/netbeans/platform/openide.compat/src/org/openide/util/WeakListener.java:921: warning: [rawtypes] found raw type: WeakReference
   [repeat]     private static final class ListenerReference extends WeakReference implements Runnable {
   [repeat]                                                          ^
   [repeat]   missing type arguments for generic class WeakReference<T>
   [repeat]   where T is a type-variable:
   [repeat]     T extends Object declared in class WeakReference
   [repeat] /home/bwalker/src/netbeans/platform/openide.compat/src/org/openide/util/WeakListener.java:922: warning: [rawtypes] found raw type: Class
   [repeat]         private static Class lastClass;
   [repeat]                        ^
   [repeat]   missing type arguments for generic class Class<T>
   [repeat]   where T is a type-variable:
   [repeat]     T extends Object declared in class Class

This work is done project wide. There are 3 remaining warnings that I was unable to get resolved. They will have to wait until later.
  • Loading branch information
BradWalker authored Apr 5, 2022
1 parent da88283 commit 04fc2a3
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public WebApp getDDRoot(FileObject fo) throws IOException {
// preparsing
error = parse(fo);
original = DDUtils.createWebApp(fo, version);
baseBeanMap.put(fo.toURL(), new WeakReference(original));
baseBeanMap.put(fo.toURL(), new WeakReference<>(original));
errorMap.put(fo.toURL(), error);
}
} else {
Expand Down Expand Up @@ -155,7 +155,7 @@ public WebApp getDDRoot(FileObject fo) throws IOException {
if (cached != null) {
return cached;
}
ddMap.put(fo.toURL(), new WeakReference(webApp));
ddMap.put(fo.toURL(), new WeakReference<>(webApp));
}
return webApp;
}
Expand Down Expand Up @@ -189,7 +189,7 @@ public WebApp getDDRootCopy(FileObject fo) throws IOException {
}

private WebAppProxy getFromCache(FileObject fo) throws IOException {
WeakReference wr = (WeakReference) ddMap.get(fo.toURL());
WeakReference<WebAppProxy> wr = ddMap.get(fo.toURL());
if (wr == null) {
return null;
}
Expand All @@ -201,7 +201,7 @@ private WebAppProxy getFromCache(FileObject fo) throws IOException {
}

private WebApp getOriginalFromCache(FileObject fo) throws IOException {
WeakReference wr = (WeakReference) baseBeanMap.get(fo.toURL());
WeakReference<WebApp> wr = baseBeanMap.get(fo.toURL());
if (wr == null) {
return null;
}
Expand Down Expand Up @@ -290,7 +290,7 @@ public void fileChanged(FileEvent evt) {
webApp.setStatus(WebApp.STATE_INVALID_OLD_VERSION);
webApp.setError(null);
}
baseBeanMap.put(fo.toURL(), new WeakReference(original));
baseBeanMap.put(fo.toURL(), new WeakReference<>(original));
errorMap.put(fo.toURL(), webApp.getError());
webApp.merge(original, WebApp.MERGE_UPDATE);
} catch (SAXException ex) {
Expand All @@ -314,7 +314,7 @@ public void fileChanged(FileEvent evt) {
if (original.getClass().equals(orig.getClass())) {
orig.merge(original,WebApp.MERGE_UPDATE);
} else {
baseBeanMap.put(fo.toURL(), new WeakReference(original));
baseBeanMap.put(fo.toURL(), new WeakReference<>(original));
}
}
} catch (SAXException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public abstract class DDMultiViewDataObject extends XmlMultiViewDataObject
implements DDProviderDataObject {


private WeakReference transactionReference = null;
private static final int HANDLE_UNPARSABLE_TIMEOUT = 2000;
private DDMultiViewDataObject.ModelSynchronizer modelSynchronizer;

Expand Down Expand Up @@ -91,9 +90,6 @@ public Reader createReader() throws IOException {
}

public void writeModel(RootInterface model) throws IOException {
if (transactionReference != null && transactionReference.get() != null) {
return;
}
FileLock dataLock = waitForLock();
if (dataLock == null) {
return;
Expand Down Expand Up @@ -169,27 +165,6 @@ protected String generateDocumentFromModel(RootInterface model) {
*/
protected abstract boolean isDocumentParseable();

// public Transaction openTransaction() {
// final XmlMultiViewDataSynchronizer.Transaction synchronizerTransaction = getModelSynchronizer().openTransaction();
// if (synchronizerTransaction == null) {
// return null;
// } else {
// Transaction transaction = new Transaction() {
// public void rollback() {
// synchronizerTransaction.rollback();
// transactionReference = null;
// }
//
// public void commit() throws IOException {
// synchronizerTransaction.commit();
// transactionReference = null;
// }
// };
// transactionReference = new WeakReference(transaction);
// return transaction;
// }
// }

private class ModelSynchronizer extends XmlMultiViewDataSynchronizer {
private long handleUnparseableTimeout = 0;
private Boolean overwriteUnparseable = Boolean.TRUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public final boolean isValid() {
public final synchronized void storeData(T data) {
CacheEntry<T> entry = new CacheEntry<>(this, data);
if (doStoreEntry(entry)) {
entryRef = new WeakReference(entry);
entryRef = new WeakReference<>(entry);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public synchronized WRAPPER getWrapper(DATA d) {
return w;
}

public WeakReference get(DATA key, WRAPPER w) {
public WeakReference<WRAPPER> get(DATA key, WRAPPER w) {
return super.put(key, new MapReference(key, w));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public abstract class XmlMultiViewDataObject extends MultiDataObject implements
private final DataCache dataCache = new DataCache();
private EncodingHelper encodingHelper = new EncodingHelper();
private transient long timeStamp = 0;
private transient WeakReference lockReference;
private transient WeakReference<FileLock> lockReference;


private MultiViewElement activeMVElement;
Expand Down Expand Up @@ -497,7 +497,7 @@ public FileLock lock() throws IOException {
throw new FileAlreadyLockedException("File is already locked by [" + current + "]."); // NO18N
}
FileLock l = new FileLock();
lockReference = new WeakReference(l);
lockReference = new WeakReference<>(l);
return l;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public void propertyChange (PropertyChangeEvent e) {
/*
* Reference which remembers which editor created stored TreeDocumentRoot.
*/
private class TreeReference extends WeakReference implements Runnable {
private class TreeReference extends WeakReference<TreeDocumentRoot> implements Runnable {

TreeReference (TreeDocumentRoot root) {
super(root, Utilities.activeReferenceQueue());
Expand Down Expand Up @@ -564,7 +564,7 @@ public void run() {

public static class CookieFactoryImpl extends CookieFactory {

private WeakReference editor;
private WeakReference<TreeEditorCookieImpl> editor;

private final XMLDataObjectLook dobj; // used while creating the editor

Expand Down Expand Up @@ -604,7 +604,7 @@ private TreeEditorCookieImpl prepareEditor() {
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("Initializing TreeEditorCookieImpl ..."); // NOI18N

TreeEditorCookieImpl cake = new TreeEditorCookieImpl (dobj);
editor = new WeakReference (cake);
editor = new WeakReference<>(cake);
return cake;
}

Expand Down
4 changes: 2 additions & 2 deletions ide/xml/src/org/netbeans/modules/xml/DTDDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public final class DTDDataObject extends MultiDataObject implements XMLDataObjec
private static final long serialVersionUID = 2890472952957502631L;

/** Synchronization implementation delegate. */
private Reference<XMLSyncSupport> refSync;
private Reference<Synchronizator> refSync;

/** Cookie Manager */
private final DataObjectCookieManager cookieManager;
Expand Down Expand Up @@ -143,7 +143,7 @@ public synchronized Synchronizator getSyncInterface() {
return sync;
}
sync = new DTDSyncSupport(this);
refSync = new WeakReference(sync);
refSync = new WeakReference<>(sync);
return sync;
}

Expand Down
4 changes: 2 additions & 2 deletions ide/xml/src/org/netbeans/modules/xml/XMLDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public final class XMLDataObject extends org.openide.loaders.XMLDataObject
private static final long serialVersionUID = 9153823984913876866L;

/** Synchronization implementation delegate. */
private Reference<XMLSyncSupport> refSync;
private Reference<Synchronizator> refSync;

/** Cookie Manager */
private final DataObjectCookieManager cookieManager;
Expand Down Expand Up @@ -256,7 +256,7 @@ public synchronized Synchronizator getSyncInterface() {
return sync;
}
sync = new XMLSyncSupport(this);
refSync = new WeakReference(sync);
refSync = new WeakReference<>(sync);
return sync;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ public void propertyChange(PropertyChangeEvent ev) {
*/
public static class TextEditorSupportFactory implements CookieSet.Factory {
/** */
private WeakReference editorRef;
private WeakReference<TextEditorSupport> editorRef;
/** */
private final XMLDataObjectLook dataObject; // used while creating the editor
/** */
Expand Down Expand Up @@ -768,7 +768,7 @@ public final TextEditorSupport createEditor() { // atomic test and set
return editorSupport;
}
editorSupport = prepareEditor();
editorRef = new WeakReference(editorSupport);
editorRef = new WeakReference<>(editorSupport);
}
editorSupport.syncMimeType();
return editorSupport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ public int[] interestedInLogLevels (AntSession session) {
private Map<AntDebugger, AntSession> runningDebuggers2 = new HashMap<>();
private Set<File> filesToDebug = new HashSet<>();
/** File => WeakReference -> ExecutorTask */
private Map<File, WeakReference> fileExecutors = new HashMap<>();
private Map<File, WeakReference<ExecutorTask>> fileExecutors = new HashMap<>();

void debugFile (File f) {
filesToDebug.add (f);
}

void fileExecutor(File f, ExecutorTask execTask) {
fileExecutors.put(f, new WeakReference(execTask));
fileExecutors.put(f, new WeakReference<>(execTask));
}

private void finishDebugging (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class DBMetaDataProvider {
// must be a weak reference -- we don't want to prevent the connection from being GCd
// it is OK to be a weak reference -- the connection is hold strongly by the DB Explorer
// while connected
private final Reference/*<Connection>*/ conn;
private final Reference<Connection> conn;
private final String driverClass;

private Map/*<String, Catalog>*/ catalogs;
Expand All @@ -76,7 +76,7 @@ public static MetaDataListener createMetaDataListener() {
}

public DBMetaDataProvider(Connection conn, String driverClass) {
this.conn = new WeakReference(conn);
this.conn = new WeakReference<>(conn);
this.driverClass = driverClass;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public Result parse(@NullAllowed FileObject file, CharSequence text, TokenSequen
/**
* Marker that javac api is not available.
*/
private static final Reference<ClassPath> NONE = new WeakReference(null);
private static final Reference<ClassPath> NONE = new WeakReference<>(null);

private static ClassPath getJavacApiJarClasspath() {
Reference<ClassPath> r = javacApiClasspath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class OpenProjectFastIndex implements ClassIndexManagerListener {
* will be released. The collection is shared between all scheduled Watchers.
*/
// @GuardedBy(self)
private Reference<Set<FileObject>> removedRoots;
private Reference<Collection<FileObject>> removedRoots;

/**
* Cached project information. Added at the first request for project icon or name,
Expand Down Expand Up @@ -287,9 +287,11 @@ private synchronized ProjectOpenWatcher getWatcher(Future f) {
if (watcher != null) {
return watcher;
}
Collection removed = removedRoots == null ? null : removedRoots.get();

Collection<FileObject> removed = removedRoots == null ? null : removedRoots.get();

if (removed == null) {
removedRoots = new WeakReference(removed = new HashSet<FileObject>());
removedRoots = new WeakReference<Collection<FileObject>>(removed = new HashSet<>());
}
watcher = new ProjectOpenWatcher(f, removed);
watchCount++;
Expand Down Expand Up @@ -552,7 +554,7 @@ static class NameIndex {

NameIndex(Project p, FileObject root, String files, List<Object[]> indices) {
this.project = p;
this.root = new WeakReference(root);
this.root = new WeakReference<>(root);
this.size = indices.size();
this.fileNames = files;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,14 +918,14 @@ Object getImplementator() {

/** Reference that also holds ref to WeakListener.
*/
private static final class ListenerReference extends WeakReference implements Runnable {
private static final class ListenerReference<T> extends WeakReference<T> implements Runnable {
private static Class lastClass;
private static String lastMethodName;
private static Method lastRemove;
private static Object LOCK = new Object();
final WeakListener weakListener;

public ListenerReference(Object ref, WeakListener weakListener) {
public ListenerReference(T ref, WeakListener weakListener) {
super(ref, Utilities.activeReferenceQueue());
this.weakListener = weakListener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public Repository call() throws Exception {
synchronized (Repository.class) {
if (lastDefLookup == c) {
lastLocalProvider = q;
lastDefLookup = new WeakReference(lkp);
lastDefLookup = new WeakReference<>(lkp);
}
}
}
Expand All @@ -459,7 +459,7 @@ public Repository getRepository() throws IOException {
static synchronized void reset() {
repository = null;
lastLocalProvider = null;
lastDefLookup = new WeakReference(null);
lastDefLookup = new WeakReference<>(null);
}
private static final ThreadLocal<FileSystem[]> ADD_FS = new ThreadLocal<FileSystem[]>();
private static boolean addFileSystemDelayed(FileSystem fs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private void internStackTrace(ThreadInfo tinfo) {
stack[i] = oldStackRef.get();
assert stack[i] != null;
} else {
steCache.put(ste, new WeakReference(ste));
steCache.put(ste, new WeakReference<>(ste));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WsdlModelerFactory {

/** Creates a new instance of WsdlModelerFactory */
private WsdlModelerFactory() {
modelers = new WeakHashMap<URL, WeakReference<WsdlModeler>>(5);
modelers = new WeakHashMap<>(5);
}

/**
Expand All @@ -56,7 +56,7 @@ public WsdlModeler getWsdlModeler(URL wsdlUrl) {
return modeler;
}
modeler = new WsdlModeler(wsdlUrl);
modelers.put(wsdlUrl, new WeakReference<WsdlModeler>(modeler));
modelers.put(wsdlUrl, new WeakReference<>(modeler));
}
return modeler;
}
Expand All @@ -65,7 +65,7 @@ private WsdlModeler getFromCache (URL url) {
if (url == null) {
return null;
}
WeakReference wr = modelers.get(url);
WeakReference<WsdlModeler> wr = modelers.get(url);
if (wr == null) {
return null;
}
Expand Down

0 comments on commit 04fc2a3

Please sign in to comment.