Skip to content

The google-java-formatter eclipse plugin doesn't change the format of my code #1077

Open

Description

@gustabart

Hi,
I drop the google-java-format-eclipse-plugin-1.20.0.jar file in dropins eclipse folder.
I set google-java-formatter in my eclipse workspace and project configuration.
However, the formatter hasen't effect over my code.

I do Ctrl-Shift+F or from the contextual menu, but the java code format remains the same.

My eclipse version is:

Eclipse IDE for Java Developers (includes Incubating components)
Version: 2023-12 (4.30.0)
Build id: 20231201-2043
OS: Linux, v.5.14.0-1052-oem, x86_64 / gtk 3.24.33, WebKit 2.42.5
Java vendor: Eclipse Adoptium
Java runtime version: 21.0.2+13-LTS
Java version: 21.0.2

I tried too with previous versions of the formatter plugin but the same result.
I thing that got my attention was the Preview. All in a same line:
image

Thanks in advance!

Activity

  1. schovjan commented on Mar 27, 2024

    @schovjan

    Hi,
    i have the same problom with latest version of STS(Version: 4.22.0.RELEASE, based on Eclipse 4.31.0.v20240229-1022) and GJF-1.21.0.

    When I run STS via terminal, i don't see any errors when trying to format code.

    Could we add Bug label to this issue?

  2. schovjan commented on Mar 27, 2024

    @schovjan

    After I added these lines at the end of file SpringToolSuite4.ini it works :)

    --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
    

    founded at https://www.eclipse.org/forums/index.php/t/1112791/

  3. wutzebaer commented on Jul 18, 2024

    @wutzebaer

    hm i dont have STS , just plain "Eclipse IDE for Java Developers" but formatting does not work for me either, but found this exception in my error log

    java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x1fc0e258) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x1fc0e258
    	at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:350)
    	at com.google.googlejavaformat.java.JavaInput.buildToks(JavaInput.java:335)
    	at com.google.googlejavaformat.java.JavaInput.<init>(JavaInput.java:277)
    	at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:270)
    	at com.google.googlejavaformat.java.SnippetFormatter.format(SnippetFormatter.java:109)
    	at com.google.googlejavaformat.java.GoogleJavaFormatter.formatInternal(GoogleJavaFormatter.java:87)
    	at com.google.googlejavaformat.java.GoogleJavaFormatter.format(GoogleJavaFormatter.java:39)
    	at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.reformat(CodeFormatterUtil.java:361)
    	at org.eclipse.jdt.internal.ui.text.java.JavaFormattingStrategy.format(JavaFormattingStrategy.java:75)
    	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.formatMaster(MultiPassContentFormatter.java:197)
    	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.format(MultiPassContentFormatter.java:143)
    	at org.eclipse.jface.text.source.SourceViewer.doOperation(SourceViewer.java:1045)
    	at org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation(ProjectionViewer.java:1468)
    	at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.doOperationCached(JavaSourceViewer.java:182)
    	at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.lambda$0(JavaSourceViewer.java:160)
    	at org.eclipse.jdt.core.JavaCore.lambda$0(JavaCore.java:6146)
    	at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5765)
    	at org.eclipse.jdt.internal.core.JavaModelManager.callReadOnly(JavaModelManager.java:5754)
    	at org.eclipse.jdt.core.JavaCore.callReadOnly(JavaCore.java:6130)
    	at org.eclipse.jdt.core.JavaCore.runReadOnly(JavaCore.java:6145)
    	at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.doOperation(JavaSourceViewer.java:160)
    	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:206)
    	at org.eclipse.ui.texteditor.TextOperationAction.lambda$0(TextOperationAction.java:130)
    	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
    	at org.eclipse.ui.texteditor.TextOperationAction.run(TextOperationAction.java:130)
    	at org.eclipse.jface.action.Action.runWithEvent(Action.java:474)
    	at org.eclipse.jface.commands.ActionHandler.execute(ActionHandler.java:124)
    	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:98)
    	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
    	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:299)
    	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:233)
    	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:174)
    	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:165)
    	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:488)
    	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:485)
    	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:204)
    	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:308)
    	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:569)
    	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:644)
    	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:439)
    	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:96)
    	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
    	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1294)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1159)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1184)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1169)
    	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1211)
    	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1207)
    	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1688)
    	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4834)
    	at org.eclipse.swt.widgets.Canvas.WM_CHAR(Canvas.java:345)
    	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4712)
    	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:340)
    	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5050)
    	at org.eclipse.swt.internal.win32.OS.DispatchMessage(Native Method)
    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3671)
    	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1151)
    	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
    	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1042)
    	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:152)
    	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:639)
    	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
    	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:546)
    	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
    	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
    	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
    	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
    	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
    	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:668)
    	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:605)
    	at org.eclipse.equinox.launcher.Main.run(Main.java:1481)
    
  4. SkylerMime commented on Oct 28, 2024

    @SkylerMime

    I'm having the same problem with google-java-format-eclipse-plugin-1.24.0 and no STS

  5. scch-michael-pfeiffer commented on Apr 8, 2025

    @scch-michael-pfeiffer

    After I added these lines at the end of file SpringToolSuite4.ini it works :)

    --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
    

    founded at https://www.eclipse.org/forums/index.php/t/1112791/

    Adding these exports to eclipse.ini after -vmargs solved the problem for me!

    -install
    @launcher.dir/
    -vmargs
    --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
    --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
    -Declipse.p2.max.threads=10
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions