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

Obscure Notes during startMopeServer #84

Open
manuEbg opened this issue Jul 1, 2021 · 3 comments
Open

Obscure Notes during startMopeServer #84

manuEbg opened this issue Jul 1, 2021 · 3 comments
Labels
question Further information is requested

Comments

@manuEbg
Copy link
Contributor

manuEbg commented Jul 1, 2021

I am not sure what I have done, but today I noticed the following notes during Compilation of the MopeLspServer.

> Task :compileJava
Note: /home/swtp/Documents/src/MopeSWTP/src/main/java/Server/MopeModelicaService.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :processResources UP-TO-DATE
> Task :classes

I cant remember if i saw them earlier... but I think they are connected to my Changes in the feature/Diagnostics Branche

Has anyone an Idea what this means?

After reading through some StackOverflow Questions i think this has something to do with unsafe Typehandling... But I am not sure where i did this in MopeModelicaService.java

@manuEbg manuEbg added the question Further information is requested label Jul 1, 2021
@CSchoel
Copy link
Contributor

CSchoel commented Jul 2, 2021

Two quick questions:

  1. Is this issue not reported in IntellIJ? Usually the IDE should already highlight any warnings.
  2. Have you tried the debug parameter -Xlint:unchecked suggested by the note?

As a general hint: This sounds like an incorrect usage of Java generics. Maybe you forgot the diamond operator (<>) or some concrete name for a generic type parameter somewhere in your code?

@CSchoel
Copy link
Contributor

CSchoel commented Jul 2, 2021

The first google result for "uses unchecked or unsafe operations" explains this quite nicely.

@CSchoel
Copy link
Contributor

CSchoel commented Jul 2, 2021

After having a quick peek into the code, I can find at least one major issue with generics in the completion method:

CompletableFuture<?> completion = server.getTextDocumentService().completion(params);

You never want to use <?> in generics, because this is essentially the equivalent of throwing your hands in the air and yelling "the fuck do I care what type this is!".

At this point, the correct return type that you get is CompletableFuture<Either<List<CompletionItem>, CompletionList>>. I admit that this is a little unwieldy, but since Java 10 you can use the type inference keyword var for this. You can think of this as the safe variant of <?>, which does not throw away the generic type information, but rather tells the compiler to determine the most fitting type for you.

So the above line should probably be changed to...

var completion = server.getTextDocumentService().completion(params);

After that, you can unpack the value properly by first checking whether you got a Java list or a CompletionList and then proceeding accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants