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

Lombok @Data formatting error #243

Closed
markckimball opened this issue Jun 18, 2017 · 9 comments
Closed

Lombok @Data formatting error #243

markckimball opened this issue Jun 18, 2017 · 9 comments

Comments

@markckimball
Copy link

Hi guys, it's possible I'm missing something. I searched for the problem, but couldn't find anything that seemed to be directly related.

When I go to format a file that has lombok.Data imported and use the @DaTa annotation (after following the wiki entry for Lombok support), an error gets sent to the output and the file doesn't get formatted. Otherwise Lombok does seem to work.

Environment
  • Operating System: Windows 10 and MacOS Sierra
  • JDK version: 1.8.0_131-b11
  • Visual Studio Code version:
  • Java extension version: 1.13.1
Steps To Reproduce
  1. Enable lombok per vs-code wiki
  2. import lombok.Data
  3. use the @DaTa annotation
  4. attempt to format document

[Trace - 8:50:41 PM] Sending request 'textDocument/formatting - (1393)'.
Params: {
"textDocument": {
"uri": "file:///.../Message.java"
},
"options": {
"tabSize": 4,
"insertSpaces": true
}
}

[Trace - 8:50:41 PM] Received response 'textDocument/formatting - (1393)' in 35ms. Request failed: Internal error, please look at the server's logs. (-32603).
[Error - 8:50:41 PM] Request textDocument/formatting failed.
Message: Internal error, please look at the server's logs.
Code: -32603
[Trace - 8:50:41 PM] Sending notification 'workspace/didChangeWatchedFiles'.
Params: {
"changes": [
{
"uri": "file://.../Message.java",
"type": 2
}
]
}

Nothing seems to be sent to the debug console.

Current Result

file doesn't get formatted and error gets sent to output

Expected Result

file gets formatted, no error

Additional Informations

I've been able to reproduce this on both Windows 10 and Sierra. Maybe I'm just missing something.

@fbricon fbricon added the bug label Jun 18, 2017
@fbricon
Copy link
Collaborator

fbricon commented Jun 18, 2017

I managed to reproduce the error. The underlying exception is

Index: 64, Size: 64
java.lang.IndexOutOfBoundsException: Index: 64, Size: 64
	at java.util.ArrayList.rangeCheck(ArrayList.java:653)
	at java.util.ArrayList.get(ArrayList.java:429)
	at org.eclipse.jdt.internal.formatter.TokenManager.get(TokenManager.java:73)
	at org.eclipse.jdt.internal.formatter.TokenManager.findIndex(TokenManager.java:166)
	at org.eclipse.jdt.internal.formatter.TokenManager.firstIndexIn(TokenManager.java:193)
	at org.eclipse.jdt.internal.formatter.SpacePreparator.visit(SpacePreparator.java:413)
	at org.eclipse.jdt.core.dom.ReturnStatement.accept0(ReturnStatement.java:135)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2782)
	at org.eclipse.jdt.core.dom.Block.accept0(Block.java:137)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2759)
	at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:635)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2782)
	at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:470)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2782)
	at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:212)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.prepareSpaces(DefaultCodeFormatter.java:362)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.prepareFormattedCode(DefaultCodeFormatter.java:203)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:160)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:143)
	at org.eclipse.jdt.ls.core.internal.handlers.FormatterHandler.format(FormatterHandler.java:74)
	at org.eclipse.jdt.ls.core.internal.handlers.FormatterHandler.formatting(FormatterHandler.java:48)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$12(JDTLanguageServer.java:309)
	at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
	at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
	at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

@fbricon
Copy link
Collaborator

fbricon commented Jun 18, 2017

@markckimball can you reproduce the issue in Eclipse proper?

@fbricon
Copy link
Collaborator

fbricon commented Jun 18, 2017

So there's a known bug between lombok and Eclipse's formatter, see projectlombok/lombok#879
See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=471825

@lukejpreston
Copy link

is there any progress on this?

I think my issue is the same.

When I add this to my settings

"java.jdt.ls.vmargs": "-javaagent:/usr/local/lib/lombok.jar -Xbootclasspath/a:/usr/local/lib/lombok.jar"

I consistently get the error

[Error - HH:MM:SS] Request textDocument/formatting failed.
  Message: Internal error, please look at the server's logs.
  Code: -32603 

@mrrobworks
Copy link

mrrobworks commented May 1, 2018

Got the same issue today. I resolved it using the latest snapshot release 1.16.21 of lombok.

User settings:
"java.jdt.ls.vmargs": "-javaagent:<path-to-lombok-edge.jar> -Xbootclasspath/a:<path-to-lombok-edge.jar>"

@fbricon
Copy link
Collaborator

fbricon commented May 1, 2018

@mrrobworks thanks for the tip. It works for me too. I've updated the wiki about using the lombok-edge solution.

Since the issue is fixed by updating lombok itself, I'm closing this issue.

@fbricon fbricon closed this as completed May 1, 2018
@gitorko
Copy link

gitorko commented May 8, 2018

@fbricon Modifying the change on windows works just fine. On linux the change gets reverted back within 5 secs. Now i have duplicate entries in linux user settings file. lombok-edge.jar is what i added and the older settings lombok.jar gets reverted in user settings file.

"java.jdt.ls.vmargs": "-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication -javaagent:"/home/user/.vscode/extensions/GabrielBB.vscode-lombok-0.9.2/server/lombok-edge.jar" -Xbootclasspath/a:"/home/user/.vscode/extensions/GabrielBB.vscode-lombok-0.9.2/server/lombok-edge.jar" -javaagent:"/home/user/.vscode/extensions/GabrielBB.vscode-lombok-0.9.2/server/lombok.jar" -Xbootclasspath/a:"/home/user/.vscode/extensions/GabrielBB.vscode-lombok-0.9.2/server/lombok.jar"",

@fbricon
Copy link
Collaborator

fbricon commented May 8, 2018

@gitorko this is obviously caused by the GabrielBB.vscode-lombok extension. Try disabling it. And open a ticket in https://github.com/GabrielBB/vscode-lombok/issues. CC @GabrielBB

@GabrielBB
Copy link
Contributor

@fbricon Just updated the extension to use Lombok 1.16.21. @gitorko Please, clean the entire java.jdt.ls.vmargs from your user settings on your linux machine and update or re-install the Lombok Extension.

@fbricon fbricon added the Lombok label Aug 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants