Skip to content

Eclipse annotation processor package crash #439

@zeroinformatique

Description

@zeroinformatique

In Eclipse 2023-09, with Gradle and the IDE annotation processor, ToothPick 3.10.
I get this error:

Java Model Exception: Error in Java Model (code 983): Invalid name specified: package org.xxx

!ENTRY org.eclipse.jdt.apt.core 4 1 2023-10-08 17:01:07.265
!MESSAGE invalid name for package:package org.xxx
!STACK 1
org.eclipse.core.runtime.CoreException: Paths must not be null.
	at org.eclipse.jdt.apt.core.internal.generatedfile.GeneratedFileManager.generateFileDuringBuild(GeneratedFileManager.java:543)
	at org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeJavaSourceOutputStream.close(IdeJavaSourceOutputStream.java:71)
	at java.base/sun.nio.cs.StreamEncoder.implClose(StreamEncoder.java:347)
	at java.base/sun.nio.cs.StreamEncoder.close(StreamEncoder.java:169)
	at java.base/java.io.OutputStreamWriter.close(OutputStreamWriter.java:252)
	at java.base/java.io.BufferedWriter.close(BufferedWriter.java:269)
	at java.base/java.io.PrintWriter.close(PrintWriter.java:415)
	at toothpick.compiler.common.ToothpickProcessor.writeToFile(ToothpickProcessor.java:147)
	at toothpick.compiler.factory.FactoryProcessor.process(FactoryProcessor.java:124)

This seems related to this issue in Eclipse:

It comes down to the processor misusing the javax.lang.model: calling Package.toString() returns the qualified name in javac, but returns 'package qualifiedName' in Eclipse! So in Eclipse we attempt to place our generated sources in package 'package com.somewhere.generated' which of course is not valid.

The fix is easy: change getPackage().toString() to getPackage().getQualifiedName().toString() in your annotation processor and the issue vanishes. This is therefore not an Eclipse bug, but rather an implementation difference. (it does not appear that toString is specified particularly in this case)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=540765

ToothPick doesn't work properly on Eclipse because of this Package name issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions