Skip to content
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

Conversation

oleg-nenashev
Copy link
Member

@oleg-nenashev oleg-nenashev commented Sep 26, 2016

Addresses 17 issues in the library, mostly related to File operations, concurrency and NITs. 34 issues are still need to be fixed.

@reviewbybees and @stephenc hence some issues come from his code

@ghost
Copy link

ghost commented Sep 26, 2016

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@oleg-nenashev
Copy link
Member Author

Well, I've definitely broken something. Self-:bug:

ObjectOutputStream oos = new ObjectOutputStream(Mode.TEXT.wrap(os));
oos.writeObject(this);
oos.flush();
try (ObjectOutputStream oos = new ObjectOutputStream(Mode.TEXT.wrap(os))) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it causes the channel close since we also close upstream channels

@oleg-nenashev
Copy link
Member Author

now it's a timeout

@jglick
Copy link
Member

jglick commented Mar 22, 2017

Failed to read test report file /scratch/jenkins/workspace/libraries/remoting/target/surefire-reports/TEST-hudson.remoting.ClassRemotingTest.xml
org.dom4j.DocumentException: Invalid byte 1 of 1-byte UTF-8 sequence. Nested exception: Invalid byte 1 of 1-byte UTF-8 sequence.

and some

java.lang.IllegalStateException: The channel has not been built yet

@@ -23,6 +23,7 @@
*/
package hudson.remoting;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import edu.umd.cs.findbugs.annotations.SuppressWarnings;
Copy link
Member

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

@@ -291,7 +294,7 @@
/**
* 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<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be ConcurrentMap as the declared type?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

@@ -271,10 +272,10 @@ public ChannelBuilder withProperty(Object key, Object value) {
}

/**
* @since TODO
* @since 2.47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would document that the backing map may be subject to concurrent modifications or (better) provide a hint/reminder that the builder is not threadsafe

@@ -98,7 +103,7 @@ public void write(int c) throws IOException {
write(new char[]{(char)c},0,1);
}

public void write(char[] cbuf, int off, int len) throws IOException {
public synchronized void write(char[] cbuf, int off, int len) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this will not introduce risk of deadlock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it makes sense to reimplement it

Copy link
Member

@stephenc stephenc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly a few questions that need answering before approval

@jglick jglick removed their assignment May 2, 2017
@oleg-nenashev
Copy link
Member Author

On DV@cloud some tests throw this (suppressed) exception. Not sure why. It is either related to the agent configuration, though it may be a regression after the migration to Java 7 Files API. Works on my machine

Caused by: java.lang.ExceptionInInitializerError
	at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
	at java.nio.file.Paths.get(Paths.java:84)
	at java.nio.file.TempFileHelper.<clinit>(TempFileHelper.java:49)
	at java.nio.file.Files.createTempDirectory(Files.java:944)
	at hudson.remoting.Util.makeResource(Util.java:60)
	at hudson.remoting.ResourceImageDirect.resolveURL(ResourceImageDirect.java:40)
	at hudson.remoting.RemoteClassLoader.findResource(RemoteClassLoader.java:432)
	at java.lang.ClassLoader.getResource(ClassLoader.java:1147)
	at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:227)
	at java.lang.Class.getResourceAsStream(Class.java:2103)
	at hudson.rem0ting.TestCallable.call(TestCallable.java:49)
	at hudson.remoting.UserRequest.perform(UserRequest.java:183)
	at hudson.remoting.UserRequest.perform(UserRequest.java:53)
	at hudson.remoting.Request$2.run(Request.java:336)
	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
	at ......remote call to north(Native Method)
	at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1567)
	at hudson.remoting.UserResponse.retrieve(UserRequest.java:283)
	at hudson.remoting.Channel.call(Channel.java:843)
	... 5 more
Caused by: java.lang.RuntimeException: default directory must be absolute
	at sun.nio.fs.UnixFileSystem.<init>(UnixFileSystem.java:54)
	at sun.nio.fs.LinuxFileSystem.<init>(LinuxFileSystem.java:39)
	at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:44)
	at sun.nio.fs.LinuxFileSystemProvider.newFileSystem(LinuxFileSystemProvider.java:37)
	at sun.nio.fs.UnixFileSystemProvider.<init>(UnixFileSystemProvider.java:56)
	at sun.nio.fs.LinuxFileSystemProvider.<init>(LinuxFileSystemProvider.java:39)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at java.lang.Class.newInstance(Class.java:379)
	at sun.nio.fs.DefaultFileSystemProvider$1.run(DefaultFileSystemProvider.java:52)
	at sun.nio.fs.DefaultFileSystemProvider$1.run(DefaultFileSystemProvider.java:43)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.nio.fs.DefaultFileSystemProvider.createProvider(DefaultFileSystemProvider.java:42)
	at sun.nio.fs.DefaultFileSystemProvider.create(DefaultFileSystemProvider.java:70)
	at java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:108)
	at java.nio.file.FileSystems$DefaultFileSystemHolder.access$000(FileSystems.java:89)
	at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:98)
	at java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:96)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:95)
	at java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:90)
	at java.nio.file.FileSystems.getDefault(FileSystems.java:176)
	at java.nio.file.Paths.get(Paths.java:84)
	at java.nio.file.TempFileHelper.<clinit>(TempFileHelper.java:49)
	at java.nio.file.Files.createTempDirectory(Files.java:944)
	at hudson.remoting.Util.makeResource(Util.java:60)
	at hudson.remoting.ResourceImageDirect.resolveURL(ResourceImageDirect.java:40)
	at hudson.remoting.RemoteClassLoader.findResource(RemoteClassLoader.java:432)
	at java.lang.ClassLoader.getResource(ClassLoader.java:1147)
	at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:227)
	at java.lang.Class.getResourceAsStream(Class.java:2103)
	at hudson.rem0ting.TestCallable.call(TestCallable.java:49)
	at hudson.remoting.UserRequest.perform(UserRequest.java:183)
	at hudson.remoting.UserRequest.perform(UserRequest.java:53)
	at hudson.remoting.Request$2.run(Request.java:336)
	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
	... 4 more

@oleg-nenashev
Copy link
Member Author

@reviewbybees ready to the review, tests are green with the current CI setup

@recampbell recampbell requested a review from a user October 30, 2017 15:36
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐝

if (touch) jar.setLastModified(System.currentTimeMillis());
if (notified.add(new Checksum(sum1,sum2)))
if (touch) {
Files.setLastModifiedTime(jar.toPath(), FileTime.fromMillis(System.currentTimeMillis()));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably all this code needs to handle InvalidPathException before merging

@oleg-nenashev
Copy link
Member Author

Will fix File#toPath() in a separate PR, there are things to cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants