stephanenicolas / toothpick

A scope tree based Dependency Injection (DI) library for Java / Kotlin / Android.
Apache License 2.0
1.12k stars 115 forks source link

Eclipse annotation processor package crash #439

Open zeroinformatique opened 1 year ago

zeroinformatique commented 1 year ago

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.