Unused public or protected field error in spotbugsmain

gradlew test is successful, returning the expected results.
However, gradlew build throws qmoney:spotbugsMain FAILED error.
The class Stock[] that houses the content parsed from Json has 4 members, out of which three are not used - tradetype, quantity and purchasedate.
I tried commenting these, but then a jackson bind error is thrown because of the type mismatch.
How do i resolve this to push my code?!

Hi @sud
Looks like you are facing challenges in the current module.

Below is a link to all the FAQ’s for the current module

Below are a few similar topics raised by other users which you might find usefull

Note - This is a BETA Feature,if you find this helpful, kindly let us know.
Feedback link - https://forms.gle/cmxN5pdTXgnwgC986

Kindly mark this as a solution if this has helped you solve your query

Hi @sud

Did you created Stock Class for Parsing .

PortfolioTrade[] stocks = objectMapper.readValue(file, PortfolioTrade[].class);

You can take advantage of PortfolioTrade class to Parse file.

Hi Ved,
I wrote a class in another java file and included it in JavaApplication - I’m not having trouble parsing. That bit is successful, the results are returned in list format.
I’m facing problems with build where the unused parameters of the stock class come up as unused.

Also, I didn’t get what you’ve defined : PortfolioTrade[] - its a user-defined class right?

Hi @sud,

First thing, you need to utilise the dto provided in the pulled code, PortfolioTrade.java.

Second, my guess is you wrote another Java file for the same purpose, defining a POJO to map the JSON objects to. That is not entirely wrong, but you might have trouble integrating it later to other parts of the project as you progress in the ME.

Lastly, the SpotBug error here simply means that you have defined some fields that aren’t being used. If it is a public or protected field, you need to use it. Else, you can make it private and access it via a getter and setter. Commenting them out won’t work since you need them for parsing the object.

I hope this helps!

Hi Shorya,

Thank you - this helped, I utilized PortfolioTrade.java. The build and test were successful in the terminal output.
However step 3 of assessment throws test cases error.
PortfolioManagerApplicationTest cases(2) have passed, whereas ModuleOneTest cases have failed.

The path qmoney/build/reports/tests/test/index.html shows success, and I don’t spot any errors/failures. Also, com.crio.warmup.stock.ModuleOneTest is empty


Glad to hear it helped.

As for failing test cases, those are hidden test cases which your code needs to clear. You won’t find them in your code yet.

There are 2 cases: mainReadFile and mainReadFileEdgeCase. Please check your code once. You shouldn’t be hardcoding any values. From the file to be read to the values to be printed, everything has be done using variables and methods.

So I did as you suggested, I took the name of the file to be read from debugOutputs. However I used get(0) to get the filename from this output.
Am facing the same error :grimacing:

You need to take the name of file to be read from the command line arguments actually :sweat_smile:
That’s what I meant when I said variables and methods. You then need to read the file using the utility method already given.

I am guessing probably because of this your tests are failing.

Yes, I took the name of the file from the command lines, passed it to valueOfArgument0 (which was already implemented for reference)
Now, in mainreadfile, I was passing/hardcoding this fileneame to resolvefilefromresources - which now am passing as a variable by reading the first element of the list returned by debugOutputs

What is the other utility method to read the file?

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.