-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-37566] - FindBugs Cleanup. Part #1 #109
Changes from all commits
ec6656e
db6bfca
41944aa
8cbe343
48eacc2
43923ac
16419b6
22aa46c
a69e125
d7ab6da
9ad7d7b
211c297
46ed670
8fef0f8
c909554
ea10aed
ef29176
6a1ebb9
d9f3596
d8a96b2
19f94f2
e9d7942
5de7469
cd99a7b
88bdff9
d791df3
114a549
426ddb3
f9fb7e7
49fbad0
d0ded00
94ded0c
f9c5a1b
c792c9a
e50cfff
88da198
570ebf1
2342b06
2072945
fca115b
92d37d5
d706dd7
9765ffb
1bb5603
91dc00e
321c31a
1f5e881
15ad2d9
a50a9a7
5b1ab6f
26fc898
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
*/ | ||
package hudson.remoting; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import edu.umd.cs.findbugs.annotations.SuppressWarnings; | ||
import hudson.remoting.CommandTransport.CommandReceiver; | ||
import hudson.remoting.PipeWindow.Key; | ||
|
@@ -46,12 +47,14 @@ | |
import java.lang.ref.WeakReference; | ||
import java.net.URL; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Date; | ||
import java.util.Hashtable; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Vector; | ||
import java.util.WeakHashMap; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
@@ -291,7 +294,7 @@ public class Channel implements VirtualChannel, IChannel, Closeable { | |
/** | ||
* Property bag that contains application-specific stuff. | ||
*/ | ||
private final Hashtable<Object,Object> properties = new Hashtable<Object,Object>(); | ||
private final ConcurrentHashMap<Object,Object> properties = new ConcurrentHashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could, will change though there is no much difference since the field is private |
||
|
||
/** | ||
* Proxy to the remote {@link Channel} object. | ||
|
@@ -662,6 +665,7 @@ private ExecutorService createPipeWriterExecutor() { | |
* This is the lowest layer of abstraction in {@link Channel}. | ||
* {@link Command}s are executed on a remote system in the order they are sent. | ||
*/ | ||
@SuppressFBWarnings(value = "VO_VOLATILE_INCREMENT", justification = "The method is synchronized, no other usages. See https://sourceforge.net/p/findbugs/bugs/1032/") | ||
/*package*/ synchronized void send(Command cmd) throws IOException { | ||
if(outClosed!=null) | ||
throw new ChannelClosedException(outClosed); | ||
|
@@ -1343,8 +1347,7 @@ public void dumpDiagnostics(@Nonnull PrintWriter w) throws IOException { | |
w.printf(" Last command sent=%s%n", new Date(lastCommandSentAt)); | ||
w.printf(" Last command received=%s%n", new Date(lastCommandReceivedAt)); | ||
|
||
// TODO: Update after the merge to 3.x branch, where the Hashtable is going to be replaced as a part of | ||
// https://github.com/jenkinsci/remoting/pull/109 | ||
// TODO: Synchronize when Hashtable gets replaced by a modern collection. | ||
w.printf(" Pending calls=%d%n", pendingCalls.size()); | ||
} | ||
|
||
|
@@ -1413,6 +1416,7 @@ public void close(@CheckForNull Throwable diagnosis) throws IOException { | |
// termination is done by CloseCommand when we received it. | ||
} | ||
|
||
//TODO: ideally waitForProperty() methods should get rid of the notify-driven implementation | ||
/** | ||
* Gets the application specific property set by {@link #setProperty(Object, Object)}. | ||
* These properties are also accessible from the remote channel via {@link #getRemoteProperty(Object)}. | ||
|
@@ -1421,7 +1425,13 @@ public void close(@CheckForNull Throwable diagnosis) throws IOException { | |
* This mechanism can be used for one side to discover contextual objects created by the other JVM | ||
* (as opposed to executing {@link Callable}, which cannot have any reference to the context | ||
* of the remote {@link Channel}. | ||
* @param key Key | ||
* @return The property or {@code null} if there is no property for the specified key | ||
*/ | ||
@Override | ||
@SuppressFBWarnings(value = "UG_SYNC_SET_UNSYNC_GET", | ||
justification = "setProperty() is synchronized in order to notify waitForProperty() methods" + | ||
"No problem with this method since it is a ConcurrentHashMap") | ||
public Object getProperty(Object key) { | ||
return properties.get(key); | ||
} | ||
|
@@ -1459,10 +1469,13 @@ public <T> T waitForProperty(ChannelProperty<T> key) throws InterruptedException | |
|
||
/** | ||
* Sets the property value on this side of the channel. | ||
* | ||
* @param key Property key | ||
* @param value Value to set. {@code null} removes the existing entry without adding a new one. | ||
* @return Old property value or {@code null} if it was not set | ||
* @see #getProperty(Object) | ||
*/ | ||
public synchronized Object setProperty(Object key, Object value) { | ||
@CheckForNull | ||
public synchronized Object setProperty(@Nonnull Object key, @CheckForNull Object value) { | ||
Object old = value!=null ? properties.put(key, value) : properties.remove(key); | ||
notifyAll(); | ||
return old; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.attribute.FileTime; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
|
@@ -69,9 +71,12 @@ protected URL lookInCache(Channel channel, long sum1, long sum2) throws IOExcept | |
File jar = map(sum1, sum2); | ||
if (jar.exists()) { | ||
LOGGER.log(Level.FINER, String.format("Jar file cache hit %16X%16X",sum1,sum2)); | ||
if (touch) jar.setLastModified(System.currentTimeMillis()); | ||
if (notified.add(new Checksum(sum1,sum2))) | ||
if (touch) { | ||
Files.setLastModifiedTime(jar.toPath(), FileTime.fromMillis(System.currentTimeMillis())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably all this code needs to handle InvalidPathException before merging |
||
} | ||
if (notified.add(new Checksum(sum1,sum2))) { | ||
getJarLoader(channel).notifyJarPresence(sum1,sum2); | ||
} | ||
return jar.toURI().toURL(); | ||
} | ||
return null; | ||
|
@@ -93,7 +98,7 @@ protected URL retrieve(Channel channel, long sum1, long sum2) throws IOException | |
"Cached file checksum mismatch: %s%nExpected: %s%n Actual: %s", | ||
target.getAbsolutePath(), expected, actual | ||
)); | ||
target.delete(); | ||
Files.delete(target.toPath()); | ||
synchronized (checksumsByPath) { | ||
checksumsByPath.remove(target.getCanonicalPath()); | ||
} | ||
|
@@ -137,7 +142,7 @@ protected URL retrieve(Channel channel, long sum1, long sum2) throws IOException | |
|
||
return target.toURI().toURL(); | ||
} finally { | ||
tmp.delete(); | ||
Files.deleteIfExists(tmp.toPath()); | ||
} | ||
} catch (IOException e) { | ||
throw (IOException)new IOException("Failed to write to "+target).initCause(e); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of the other SuppressWarnings import