Bug 573833 - -processorpath ignored if specified before -classpath
Summary: -processorpath ignored if specified before -classpath
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.20   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-28 07:50 EDT by Julian Honnen CLA
Modified: 2024-01-08 06:31 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Honnen CLA 2021-05-28 07:50:38 EDT
I'm trying to get a tycho build with an annotation processor to work, but ECJ can't find the annotation processor class.

I've found that the order of the arguments matters. Specifying the classpath before processorpath works correctly:

java -cp "C:\Users\visjho\.p2\pool\plugins\org.eclipse.jdt.compiler.apt_1.3.1300.v20210419-1022.jar;C:\Users\visjho\.p2\pool\plugins\org.eclipse.jdt.core_3.26.0.v20210524-0947.jar" org.eclipse.jdt.internal.compiler.batch.Main -11 -classpath <classpath> -processor some.annotation.Processor -processorpath path/to/processor.jar Source.java

But when I specify the -processorpath first (like tycho does), the processor can't be found:

java -cp "C:\Users\visjho\.p2\pool\plugins\org.eclipse.jdt.compiler.apt_1.3.1300.v20210419-1022.jar;C:\Users\visjho\.p2\pool\plugins\org.eclipse.jdt.core_3.26.0.v20210524-0947.jar" org.eclipse.jdt.internal.compiler.batch.Main -11 -processorpath path/to/processor.jar -classpath <classpath> -processor some.annotation.Processor Source.java

1. ERROR in Source.java (at line 0)
        /*******************************************************************************
        ^
Internal compiler error: java.lang.ClassNotFoundException: some.annotation.Processor at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)



Looking at the source code, the processorpath is ignored in the second invocation:

1) EclipseFileManager.handleOption for -processorpath
   - sets ANNOTATION_PROCESSOR_PATH location and HAS_PROCESSORPATH flag
2) EclipseFileManager.handleOption for -cp
   - sees that HAS_PROCESSORPATH is set and initializes the ANNOTATION_PROCESSOR_MODULE_PATH location with the classpath

	if ((this.flags & EclipseFileManager.HAS_PROCESSORPATH) == 0) {
		setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, classpaths);
	} else if ((this.flags & EclipseFileManager.HAS_PROC_MODULEPATH) == 0) {
		if (this.isOnJvm9)
			setLocation(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, classpaths);
	}

3) BatchAnnotationProcessorManager.configure finds a non-null ANNOTATION_PROCESSOR_MODULE_PATH location and prefers that over ANNOTATION_PROCESSOR_PATH



In the first, working, invocation the -cp option initializes the ANNOTATION_PROCESSOR_PATH location instead which is afterwards overwritten by the -processorpath option.


This effectively breaks the -processorpath option in tycho when running on java9+ as you can't control the order of the -classpath argument.
Using the --processor-module-path option instead (with a regular jar) seems to work though.
Comment 1 Eclipse Genie CLA 2023-05-25 16:07:47 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Falko Modler CLA 2024-01-08 06:31:47 EST
This is still an issue as of ECJ 3.36.0.

I had to add a workaround to plexus-compiler-eclipse (which is kind of the adapter for maven-compiler-plugin):
https://github.com/codehaus-plexus/plexus-compiler/pull/350