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

Invalid formatter profile name setting causes errors #1761

Closed
rgrunber opened this issue May 5, 2021 · 1 comment · Fixed by #1762
Closed

Invalid formatter profile name setting causes errors #1761

rgrunber opened this issue May 5, 2021 · 1 comment · Fixed by #1762
Assignees
Milestone

Comments

@rgrunber
Copy link
Contributor

rgrunber commented May 5, 2021

java.format.settings.url should point to a valid formatter file and do not set java.format.settings.profile at all. Formatting should work as expected.

Now change java.format.settings.profile to a name that doesn't exist in the formatter file. You'll need to restart the language server as it seems changing the profile name does not affect the formatter used automatically.

You should see the following error :

[Error - 2:23:37 PM] May 5, 2021, 2:23:37 PM Cannot invoke "java.util.Map.entrySet()" because "oldSettings" is null
Cannot invoke "java.util.Map.entrySet()" because "oldSettings" is null
java.lang.NullPointerException: Cannot invoke "java.util.Map.entrySet()" because "oldSettings" is null
	at org.eclipse.jdt.internal.ui.preferences.formatter.ProfileVersionerCore.updateAndComplete(ProfileVersionerCore.java:98)
	at org.eclipse.jdt.ls.core.internal.managers.FormatterManager.readSettingsFromStream(FormatterManager.java:171)
	at org.eclipse.jdt.ls.core.internal.managers.StandardProjectsManager.configureSettings(StandardProjectsManager.java:276)
	at org.eclipse.jdt.ls.core.internal.managers.StandardProjectsManager$3.preferencesChange(StandardProjectsManager.java:534)
	at org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager$1.run(PreferenceManager.java:212)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager.preferencesChanged(PreferenceManager.java:215)
	at org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager.update(PreferenceManager.java:183)
	at org.eclipse.jdt.ls.core.internal.preferences.StandardPreferenceManager.update(StandardPreferenceManager.java:66)
	at org.eclipse.jdt.ls.core.internal.handlers.BaseInitHandler.handleInitializationOptions(BaseInitHandler.java:116)
	at org.eclipse.jdt.ls.core.internal.handlers.InitHandler.handleInitializationOptions(InitHandler.java:72)
	at org.eclipse.jdt.ls.core.internal.handlers.BaseInitHandler.initialize(BaseInitHandler.java:64)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.initialize(JDTLanguageServer.java:235)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)
	at org.eclipse.jdt.ls.core.internal.ParentProcessWatcher.lambda$0(ParentProcessWatcher.java:123)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
	at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at java.base/java.lang.Thread.run(Thread.java:831)

One might delete the profile name and restart but that still won't fix things because the profile name is now just an empty string, and only a null value would have properly loaded the (default?) settings. See https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/FormatterManager.java#L79 .

Update : Seems like an exception could be thrown if the profile name doesn't match anything, or fSettings could be initialized and passed forward. I'd be inclined to have an empty profile name behave the same way as null does.

Update 2 : Changing the formatter file works perfectly. I think it's just changing the profile name that requires a restart.

@rgrunber
Copy link
Contributor Author

rgrunber commented May 5, 2021

Looking at https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/StandardProjectsManager.java#L531 , I guess we would also need to add getFormatterProfileName() if we wanted to react to changes there. Otherwise, changing it would have no effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants