eclipse-jdt / eclipse-jdt/eclipse.jdt.core
[formatter] IndexOutOfBoundsException in applying formatter to code having errors
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
Relates to:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=471825
https://github.com/vi-eclipse/Eclipse-JDT/issues/10
### How to reproduce the bug:
The code given in this comment: https://bugs.eclipse.org/bugs/show_bug.cgi?id=471825#c11
or
```
package testproject;
public class Application extends B {
protected int f = 11;
```
###
As far I can understand, it fails because we ignore errors if the kind is K_COMPILATION_UNIT: https://github.com/eclipse-jdt/eclipse.jdt.core/blob/master/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java#L317
and it proceeds to find the closing bracket.
For me, if a code has errors then we should not format it at all but I can't find any comment on why `ignoreErrors ` was set to true for K_COMPILATION_UNIT in the original code which was introduced in this commit: https://github.com/eclipse-jdt/eclipse.jdt.core/commit/b0e753009ffb9bf0d92f75f621fb0d6188adb57e
One possible fix could be to not ignore errors: https://github.com/eclipse-jdt/eclipse.jdt.core/pull/1434
But it fails tests and before fixing those tests I would like to confirm this is the expected behavior.
Contributor guide
Assessment
This issue has not been assessed yet.