Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 568640

Summary: [save actions][clean up] save actions fail when @JsonProperty(access = Access.READ_ONLY) is present
Product: [Eclipse Project] JDT Reporter: Giacomo Baso <giacomo.baso>
Component: CoreAssignee: Fabrice Tiercelin <fabrice.tiercelin>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: carsten.hammer, fabrice.tiercelin, jjohnstn, Lars.Vogel
Version: 4.17   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
eclipse log none

Description Giacomo Baso CLA 2020-11-09 07:06:47 EST
Error log:

The save participant 'Code Clean Up' caused an exception: java.lang.IllegalArgumentException: startPos = 2120 and length is -1609.
This breaks the rule that lengths are not allowed to be negative. Affected Node:
class org.eclipse.jdt.core.dom.MemberValuePair: access=Access.READ_ONLY. See the error log for details.

Using openjdk 11.0.9, jackson 2.11.2
Comment 1 Andrey Loskutov CLA 2020-11-09 15:20:56 EST
Please attach full error log.
Comment 2 Giacomo Baso CLA 2020-11-10 14:07:40 EST
Created attachment 284724 [details]
eclipse log
Comment 3 Andrey Loskutov CLA 2020-11-11 12:14:45 EST
Fabrice, could you please take a look?

Stack: 

java.lang.IllegalArgumentException: startPos = 2118 and length is -1607.
This breaks the rule that lengths are not allowed to be negative. Affected Node:
class org.eclipse.jdt.core.dom.MemberValuePair: access=Access.READ_ONLY
	at lombok.eclipse.agent.PatchDiagnostics.setSourceRangeCheck(PatchDiagnostics.java:36)
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2538)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2587)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1097)
	at org.eclipse.jdt.core.dom.ASTConverter.setModifiers(ASTConverter.java:5591)
	at org.eclipse.jdt.core.dom.ASTConverter.setModifiers(ASTConverter.java:5541)
	at org.eclipse.jdt.core.dom.ASTConverter.setModifiers(ASTConverter.java:5650)
	at org.eclipse.jdt.core.dom.ASTConverter.convertToFieldDeclaration(ASTConverter.java:3619)
	at org.eclipse.jdt.core.dom.ASTConverter.checkAndAddMultipleFieldDeclaration(ASTConverter.java:541)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:201)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3302)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1513)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:323)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1231)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:820)
	at org.eclipse.jdt.core.manipulation.CoreASTProvider$1.run(CoreASTProvider.java:272)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.jdt.core.manipulation.CoreASTProvider.createAST(CoreASTProvider.java:264)
	at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:197)
	at org.eclipse.jdt.core.manipulation.SharedASTProviderCore.getAST(SharedASTProviderCore.java:138)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:167)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.run(SelectionListenerWithASTManager.java:152)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Comment 4 Fabrice Tiercelin CLA 2020-11-11 12:28:38 EST
Can you reproduce the bug?

If yes, can you reproduce it with the minimum checked options in Save Actions settings (Window -> Preference -> Java -> Editor -> Save Actions -> Configure...) ?

Are you using Eclipse 2020-09 or a recent build? If yes, which build?
Comment 5 Giacomo Baso CLA 2020-11-11 14:11:13 EST
I'm using Eclipse 2020-09 JEE. Bug is reproducible with a clean workspace and only "organize imports" checked, on a new Spring Boot 2.3.4 project with just a single class:

```
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;

import lombok.Data;

@Data
public class MyDto {

	private Long id;
	@JsonProperty(access = Access.READ_ONLY)
	private String test; 
	
}
```

From the log it looks like a weird interaction with the lombok agent? I tried updating the lombok agent to version 1.18.16 (latest, from boot managed version 1.18.12) and the problem was not present. Still, the error message is not helpful and there could be something else going on.
Comment 6 Fabrice Tiercelin CLA 2020-11-11 14:19:24 EST
I already faced issues on save actions using Lombok. Unfortunately, I have never found a solution :( Those issues seem hard to solve because the bytecode and the source do not match.

The only feature I can implement would be to disable save actions on a class in which Lombok is used. Others? Do I do that?
Comment 7 Giacomo Baso CLA 2020-11-11 14:25:22 EST
As a heavy user of both lombok and save actions, I can say that for me it would be highly undesirable, I'd rather live with some breakage every now and then. Can I suggest a checkbox in the save action menu, toggable when lombok agent is detected, to enable/disable what you proposed?
Comment 8 Fabrice Tiercelin CLA 2020-11-11 14:57:05 EST
Beware, Save Actions on Lombok can also break your code without throwing errors.
Comment 9 Giacomo Baso CLA 2021-03-25 14:07:59 EDT
Bug seems to be fixed in Eclipse 2021-03