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

Codequality #117

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

Codequality #117

wants to merge 5 commits into from

Conversation

CSchoel
Copy link
Contributor

@CSchoel CSchoel commented Aug 6, 2021

I created this pull request prematurely in order to be able to provide a comprehensive code review. This branch is still work in progress.

@manuEbg
Copy link
Contributor

manuEbg commented Aug 6, 2021

I canceled the workflow because testing already took 1 hour and 50 Minutes. So I think there is something wrong...
Maybe @CptKaNe should have a look at this

Copy link
Contributor Author

@CSchoel CSchoel left a comment

Choose a reason for hiding this comment

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

I went through the changes and provided feedback as detailed as possible. There are a few misconceptions here that should be addressed.

Comment on lines 30 to 35
static {
socket = null;
client = null;
menu = null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not the solution you are looking for. ✋

Static blocks are only seldom useful (as "constructors" for static classes, for example).

The real issue here is that the variables are static, but they are assigned in a non-static context (that is the constructor). You should think about which makes more sense: Having multiple ConsoleClientLauncher objects with different values for these variables, or having one single ConsoleClientLauncher that uses only static methods. (Or option 3: Use the singleton pattern.)

Copy link
Contributor

Choose a reason for hiding this comment

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

You are absolutely right, I was insecure about supporting more clients at the same time, so i was trying to find a proper solution. Because if there is only one Launcher with static methods, multiclients are not possible or am i mixing things up in this case?

Comment on lines 43 to 45
public static void setExecutorPool() {
executor = Executors.newFixedThreadPool(2);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am confused why this is required by SonarQube. This looks like an unnecessary method that could be replaced by the one line of code that it contains.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CptKaNe Can you tell me what the error is that you tried to fix here?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, it also was referring of a static field (executor) in a non static context, but i guess you already find out because of the further feedback below. Lots of work to do for me ;-)

Comment on lines 32 to 37
static {
serverSocket = null;
server = null;
configObject = null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, this is not what you want here. Decide how the class should be used: As instance, as static class, or as singleton, and refactor it accordingly.


public void launchServer() {

System.setProperty(Log4jLoggerAdapter.ROOT_LOGGER_NAME, "TRACE");

logger.info("Server socket listening on port " + configObject.port );
System.out.flush();
executor = Executors.newCachedThreadPool();
//executor = Executors.newCachedThreadPool();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no need to keep deleted code as comments in a git repository. That's what version control is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, creating the executor in main() instead of launchServer() means that the tests now fail with a null pointer exception, since the ServerIntegrationTest calls launchServer() but not main().

Copy link
Contributor

Choose a reason for hiding this comment

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

Well this is probably because i was not into the project for weeks and do not know every change since then, but yesterday I already had the feeling, theres something wrong with these changes. I will appreciate it.

@@ -55,6 +57,9 @@ public void didChangeWatchedFiles(DidChangeWatchedFilesParams didChangeWatchedFi
case "Version":
result = modelicaService.getCompilerVersion();
break;
default:
result = CompletableFuture.completedFuture(error);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this really what you want? It is a design choice, but inside a Java environment I would opt for a more rigid approach: When you get an unexpected input, you throw a InputMismatchException.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the hint!

@CSchoel
Copy link
Contributor Author

CSchoel commented Aug 6, 2021

I canceled the workflow because testing already took 1 hour and 50 Minutes. So I think there is something wrong...
Maybe @CptKaNe should have a look at this

I have found the culprit: It is actually a NullPointerException, because the executor is not initialized for the ServerIntegrationTest. This raises another issue: Why does GH actions not pick up this error as it happens. I know there is an issue with GH action not recognizing process exits correctly, but I did not think this would be the case for a simple Gradle task.

@CSchoel CSchoel changed the base branch from main to dev August 13, 2021 09:09
@CSchoel
Copy link
Contributor Author

CSchoel commented Aug 13, 2021

Switched target branch to dev, so that we can actually use this pull request.

- added exceptions for workspaceservice
- updated syntax of commands, now start with lower letter
- Tried to implement the singleton pattern, but removed this changes because they were wrong
- ignored some unneccessary code smells from sonarqube
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants