Rudolf-Barbu / Ward

Server dashboard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IndexOutOfBoundsException when setting RamType

NangiDev opened this issue · comments

When running the code on my local computer and trying to load the dashboard I get 404 error because when trying to fetch physical memory type it returns an empty list.

Expected Behavior

If not being able to determine memory type it should not crash, but rather state so in the interface.

Current Behavior

404 errer page when trying to navigate to dashboard

Possible Solution

Check length of list before getting memory type and take action depending on content.
A simple if-else-statement would work or a stream.

Steps to Reproduce

  1. Clone repo
  2. Run mvn clean install
  3. Start Ward server
  4. Navigate to localhost: in web browser

Context (Environment)

OS: Ubuntu 18.04
JDK: OpenJDK-11.0.5
Browser: Firefox

I just wanted to initially run the code to look on possible ways of dockerize it.
Workaround for now is to add an if-statement around the code

Detailed Description

globalMemory.getPhysicalMemory() in empty when trying to get ram type to display on dashboard. It then throws IndexOutOfBoundsException and displays 404 error on dashboard

Possible Implementation

Replace row 75 in InfoService.java with:

List<PhysicalMemory> physicalMem = globalMemory.getPhysicalMemory();
if (physicalMem.isEmpty()) {
    infoDto.setRamType("Unknown");
} else {
    infoDto.setRamType(physicalMem.get(0).getMemoryType());
}

Misc

I saw that there already is an issue to refactor #10 this class so I am guessing it might get resolved at the same time.

Stupid question, bit still you ran .jar with sudo ? Because without sudo oshi library can not get info from dmidecode.
Other question why you got 404 page error but not the 500. I will test this and do Java refactoring.

I sat down this morning to investigate further and I did find (in the documentation ofc :bowtie:) that I needed elevated permission. So running the jar with sudo worked 👍

Running the jar as sudo is not a solution for me though because I run it in docker. Any suggestions?

Yeah 500 Internal server would be a better warning

I merged your pull request. And i do not understand why you got 404 error page instead of 500. I tested on Windows, and Linux without docker. And i got properly error page. May be cause of a 404 error hiding in the docker usage. But i never used ii and i can not help in this case.