I'm marking this issue for first-timers-only. That means that I will only accept a PR for this one from someone who's never contributed to open source before. This one is easy (but don't make that statement make you feel bad if you have a hard time with it, there's more to contributing to open source than changing lines of code, especially if it's your first time). I'll hold your hand through this if you need me to. :-)
As noted in this report, the lazy initialization of a list in WindowsUSBDevice is not thread safe. If two threads call getUsbDevices() simultaneously they could both pass the null check and then both attempt to modify the same variable.
Create a thread-safe lazy initialization using OSHI's Memoizer class.
Here are the steps to get a PR merged here.
WindowsUsbDevice class:getControllerDeviceIdList() method to take no arguments. Inside the method, get the wmiQueryHandler by copying from line 136. if (controllerDeviceIds == null) conditional controllerDeviceIds variable with a differently named local variable in the method. private static Supplier<List<String>> controllerDeviceIds = Memoizer
.memoize(WindowsUsbDevice::getControllerDeviceIdList);getUsbDevices() method instead of calling the old method, instead fetch from the memoizer: List<String> controllerDeviceIdList = controllerDeviceIds.get();Hi, I have never contributed to a project before. Can I try this out?
You certainly may!
I have a question about a compiling error. I just downloaded the repository onto my device, as well as the most recent versions of jGrasp and Java. When I tried to compile the code, I received many error messages along the lines of "ParseUtil.java:40: error: package org.slf4j does not exist" and other similar errors. Did I clone the project incorrectly? Sorry, I'm really a beginner to Git and open-source projects.
The project has a few dependencies, particularly slf4j (and whatever logging framework you want to use) and jna/jna-platform. These are described in the pom.xml file which is used by the Maven dependency manager.
I'm not familiar with jGrasp, as I use Eclipse, but see if the documentation mentions Maven integration.
I see. Thank you for the clarification!
If you can't use Maven you can also download the jar files for all the dependencies and put them in a library where you add them as dependencies on the classpath. However, it's probably well worth your effort to try to set up an IDE that uses Maven. (Or Gradle or other dependency managers.)
Thanks! I decided to go download Eclipse just for the benefit of standardization.
This SO answer is helpful.
Also you'll want to set up your editing format to match OSHI's. We use the "Sun Java Conventions" except with 4 space indent instead of tabs. You can import the formatting conventions from here.
Hi, I have just committed the changes and pushed them to my fork. I am a little confused about how to create a pull request. Can you walk me through that process?
Go to your github site. Look for where it says "This branch is 1 commit ahead of oshi:master." To the right of that is a button to create a pull request.
I've submitted the pull request. Thank you for all the help!
Great job! Now for the code review!