Hotswap file not found error. Running works fine.

My Project runs just fine. Even the "missing" code works. But when I want to hotswap it fails with errors like this one with a lot of files. /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java:17: Fehler: Failed to parse source file: src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java (Datei oder Verzeichnis nicht gefunden) public class TestDiscordCommand extends AbstractSingleCommand { ^ → Reason found: different working directoreis between tasks set in run config
185 Replies
JavaBot
JavaBot4d ago
This post has been reserved for your question.
Hey @Hype_the_Time! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st4d ago
Do the listed files exist? What are these classes supposed to do? The log seems like a normal Gradle build - I don't see hot swapping there
Hype_the_Time
Hype_the_TimeOP4d ago
they are command implementation for what shall happen when the command gets executed. the annotation presents the id, name, description and some other paramters that i use for registering
dan1st
dan1st4d ago
Can you run gradle compileJava? For example there's TestDiscordCommand - does that one exist?
Hype_the_Time
Hype_the_TimeOP4d ago
intelij path taken: /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java seems identical to me at least
dan1st
dan1st4d ago
Are you using Kotlin in that project?
Hype_the_Time
Hype_the_TimeOP4d ago
not sure whther its used but should be configured hm yeah its a compile java problem i have an idea what it could be it says main/src/main in here but the path it describes is src/main what if the configured path is bad
dan1st
dan1st4d ago
so the sources are in src/main? Does the error also occur with that command or not?
Hype_the_Time
Hype_the_TimeOP4d ago
i devided anjnotation processor and the main project in 2 sub projects yes it occurs
dan1st
dan1st4d ago
Where did you specify you are using src/main instead of src/main/java? Gradle uses src/main/java unless you configured it differently
Hype_the_Time
Hype_the_TimeOP4d ago
No description
dan1st
dan1st4d ago
Is that the source folder? But I asked about how you specified it not how IntelliJ displays it
Hype_the_Time
Hype_the_TimeOP4d ago
No description
dan1st
dan1st4d ago
seems like you are using src/main/java
Hype_the_Time
Hype_the_TimeOP4d ago
in the sub project
dan1st
dan1st4d ago
there's a difference between source folders and modules
Hype_the_Time
Hype_the_TimeOP4d ago
yeah that was my oiriginal idea as well but though it may think of main dir since it used to be only /src isntead of main src (main being gralde subproject name too) though it might be a missunderstanding of mine that could cause it non the less
dan1st
dan1st4d ago
What is the full path of TestDiscordCommand.java?
Hype_the_Time
Hype_the_TimeOP4d ago
.
dan1st
dan1st4d ago
and that file exists there?
Hype_the_Time
Hype_the_TimeOP4d ago
yes i used copy path from intelij on that file maybe its relevant. I normally use springs bootjar. and it is slightly modified but nothing i would see as a giveaway since that one works. tasks.named<BootJar>("bootJar") { mainClass.set("de.hype.bbsentials.server.Main") archiveFileName.set("bbsentialsonlineboot.jar") }
dan1st
dan1st4d ago
shouldn't make a difference if compilation fails What happens when commenting all Kotlin stuff in the build.gradle files?
Hype_the_Time
Hype_the_TimeOP4d ago
No description
Hype_the_Time
Hype_the_TimeOP4d ago
still fails
dan1st
dan1st4d ago
Can you run the following command in a terminal?
file /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java:17: Fehler: Failed to parse source file: src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java
file /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java:17: Fehler: Failed to parse source file: src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java
my fault
Hype_the_Time
Hype_the_TimeOP4d ago
thats not a command no?
dan1st
dan1st4d ago
copied too much
Hype_the_Time
Hype_the_TimeOP4d ago
just file?
dan1st
dan1st4d ago
file /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java
file /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java
or
head /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java
head /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java
these are Linux commands that should attempt to open the file the error sais it cannot find the file in some way so it'd be interesting to see what the standard Linux CLI tools think of that
Hype_the_Time
Hype_the_TimeOP4d ago
:~$ file /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java
/home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java: Java source, ASCII text, with very long lines (786)
:~$ file /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java
/home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java: Java source, ASCII text, with very long lines (786)
dan1st
dan1st4d ago
and running gradle compileJava really gives you
/home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java:17: Fehler: Failed to parse source file: src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java (Datei oder Verzeichnis nicht gefunden)
?
Hype_the_Time
Hype_the_TimeOP4d ago
No description
dan1st
dan1st4d ago
Can you use the command line and not IntelliJ for it?
Hype_the_Time
Hype_the_TimeOP4d ago
ig
dan1st
dan1st4d ago
or close IntellIJ and then run it maybe btw you might need to do ./gradlew compileJava or similar to use Gradle from your project
Hype_the_Time
Hype_the_TimeOP4d ago
$ ./gradlew compileJava Path for java installation '/usr/lib/jvm/openjdk-17' (Common Linux Locations) does not contain a java executable
Task :annotation-proccessor:compileJava FAILED
/home/spieler/IdeaProjects/BBsentials-Server/annotation-proccessor/src/main/java/de/hype/bbsentials/compilation/processors/DiscordButtonAnnotationProcessor.java:227: error: cannot find symbol typeElement = (TypeElement) typeUtils.asElement(newTypes.getFirst()); ^ symbol: method getFirst() location: variable newTypes of type List<? extends TypeMirror> /home/spieler/IdeaProjects/BBsentials-Server/annotation-proccessor/src/main/java/de/hype/bbsentials/compilation/processors/DiscordButtonAnnotationProcessor.java:230: error: cannot find symbol return methods.getFirst().getThrownTypes().stream().map(TypeName::get).toList(); ^ symbol: method getFirst() location: variable methods of type List<ExecutableElement> 2 errors FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':annotation-proccessor:compileJava'.
Compilation failed; see the compiler error output for details.
* Try:
Run with --info option to get more log output. Run with --scan to get full insights.
BUILD FAILED in 1s when i changed to java 17 as supported (via commandline) intelij same error
dan1st
dan1st4d ago
oh, that's a different error seems like you aren't using JDK 21 Do you have JDK 21 on your system?
Hype_the_Time
Hype_the_TimeOP4d ago
linux java package is 17 i have downloaded the othger and set paths for it but thats intelij not gradlew or sth probably
dan1st
dan1st4d ago
Where is the other one installed?
Hype_the_Time
Hype_the_TimeOP4d ago
cusom path somewhere in user home i think
dan1st
dan1st4d ago
so you can tell Gradle to use that one by setting the JAVA_HOME so
export JAVA_HOME=/home/spieler/PATH/TO/YOUR/JDK
gradle build
export JAVA_HOME=/home/spieler/PATH/TO/YOUR/JDK
gradle build
Hype_the_Time
Hype_the_TimeOP4d ago
its unpack jdk. do i need to set it to sth jdk/lib/java or sth i remeber there was a subfile named java do i need to link to that 1? also shouldnt I use ./gradlew build?
dan1st
dan1st4d ago
you can idk where your JDK is maybe in /home/spieler/.jdks?
Hype_the_Time
Hype_the_TimeOP4d ago
yes
dan1st
dan1st4d ago
Did you find it
Hype_the_Time
Hype_the_TimeOP4d ago
export JAVA_HOME=~/.jdks/jbr_jcef-21.0.3-linux-x64-b509.4/
dan1st
dan1st4d ago
FYI gradle build includes gradle compileJava (normally) and then run the gradle command in the same terminal
Hype_the_Time
Hype_the_TimeOP4d ago
spieler@spiele-pc:~/IdeaProjects/BBsentials-Server$ ./gradlew build Path for java installation '/usr/lib/jvm/openjdk-17' (Common Linux Locations) does not contain a java executable
Task :main:compileJava FAILED
Hinweis: Generating start .... Hinweis: OpenRoleSelectorButtonImplementation end Hinweis: BroadcastPrivateMegaLobbySearchMessageButtonImplementation Hinweis: BroadcastPrivateMegaLobbySearchMessageButtonImplementation end Hinweis: Generating done /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java:17: Fehler: Failed to parse source file: src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java (Datei oder Verzeichnis nicht gefunden) public class TestDiscordCommand extends AbstractSingleCommand { ^ /home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/organisation/ClearDiscordCommand.java:20: Fehler: Failed to parse source file: src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/organisation/ClearDiscordCommand.java (Datei oder Verzeichnis nicht gefunden) public class ClearDiscordCommand extends AbstractSingleCommand { ..... Hinweis: Processing over Hinweis: Modal Processing start Hinweis: Modal Processing done 47 Fehler FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':main:compileJava'.
Compilation failed; see the compiler error output for details.
* Try:
Run with --info option to get more log output. Run with --scan to get full insights.
BUILD FAILED in 3s 8 actionable tasks: 6 executed, 2 up-to-date
dan1st
dan1st4d ago
oh wait these come from the annotation processor
Hype_the_Time
Hype_the_TimeOP4d ago
my first though too but no these are used but not generated by it
dan1st
dan1st4d ago
Why not? yeah but the error comes from the annotation processor Can you attach a debugger to the annotation processor?
Hype_the_Time
Hype_the_TimeOP4d ago
yeah but they arent generated by it
dan1st
dan1st4d ago
so?
Hype_the_Time
Hype_the_TimeOP4d ago
they are used but no generated
dan1st
dan1st4d ago
if the annotation processor wants to use something but has an issue with it, it still fails
Hype_the_Time
Hype_the_TimeOP4d ago
No description
Hype_the_Time
Hype_the_TimeOP4d ago
where do you want me to attach it? WAIT i have an idea
dan1st
dan1st4d ago
Can you run ./gradlew build --no-daemon -Dorg.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005?
Hype_the_Time
Hype_the_TimeOP4d ago
CompilationUnit cu = StaticJavaParser.parse(new File(Paths.get("src/main/java", filePath).toString()));
dan1st
dan1st4d ago
and then create a "Remote Debugging" run configuration
Hype_the_Time
Hype_the_TimeOP4d ago
ive got it attached just no clue where to where put its breakpoint
dan1st
dan1st4d ago
in the process() method
Hype_the_Time
Hype_the_TimeOP4d ago
i remebered the thing how to atatch last time you explained
dan1st
dan1st4d ago
yeah that sounds like causing issues like that
Hype_the_Time
Hype_the_TimeOP4d ago
it having basically being the whole class which is 500 lines isnt making it easier to say where to put it i though wait parse? parse could be the hjava thingie question is why is only compilejava affected
dan1st
dan1st4d ago
idk but maybe it runs javac differently
Hype_the_Time
Hype_the_TimeOP4d ago
or rather why is bootjar not
dan1st
dan1st4d ago
sure about that? normally you shouldn't even be able to run bootjar without compileJava
Hype_the_Time
Hype_the_TimeOP4d ago
18:22:34: Executing 'bootJar -Dorg.gradle.daemon=false'…

Starting Gradle Daemon...
Connected to the target VM, address: '127.0.0.1:37853', transport: 'socket'
Gradle Daemon started in 719 ms
Path for java installation '/usr/lib/jvm/openjdk-17' (Common Linux Locations) does not contain a java executable
> Task :annotation-proccessor:checkKotlinGradlePluginConfigurationErrors SKIPPED
> Task :annotation-proccessor:compileKotlin NO-SOURCE
> Task :annotation-proccessor:compileJava UP-TO-DATE
> Task :annotation-proccessor:processResources NO-SOURCE
> Task :annotation-proccessor:classes UP-TO-DATE
> Task :annotation-proccessor:jar UP-TO-DATE
> Task :main:checkKotlinGradlePluginConfigurationErrors SKIPPED
> Task :main:compileKotlin UP-TO-DATE
> Task :main:compileJava UP-TO-DATE
> Task :main:processResources UP-TO-DATE
> Task :main:classes UP-TO-DATE
> Task :main:bootJar

BUILD SUCCESSFUL in 7s
6 actionable tasks: 1 executed, 5 up-to-date
18:22:42: Execution finished 'bootJar -Dorg.gradle.daemon=false'.
Disconnected from the target VM, address: '127.0.0.1:37853', transport: 'socket'
18:22:34: Executing 'bootJar -Dorg.gradle.daemon=false'…

Starting Gradle Daemon...
Connected to the target VM, address: '127.0.0.1:37853', transport: 'socket'
Gradle Daemon started in 719 ms
Path for java installation '/usr/lib/jvm/openjdk-17' (Common Linux Locations) does not contain a java executable
> Task :annotation-proccessor:checkKotlinGradlePluginConfigurationErrors SKIPPED
> Task :annotation-proccessor:compileKotlin NO-SOURCE
> Task :annotation-proccessor:compileJava UP-TO-DATE
> Task :annotation-proccessor:processResources NO-SOURCE
> Task :annotation-proccessor:classes UP-TO-DATE
> Task :annotation-proccessor:jar UP-TO-DATE
> Task :main:checkKotlinGradlePluginConfigurationErrors SKIPPED
> Task :main:compileKotlin UP-TO-DATE
> Task :main:compileJava UP-TO-DATE
> Task :main:processResources UP-TO-DATE
> Task :main:classes UP-TO-DATE
> Task :main:bootJar

BUILD SUCCESSFUL in 7s
6 actionable tasks: 1 executed, 5 up-to-date
18:22:42: Execution finished 'bootJar -Dorg.gradle.daemon=false'.
Disconnected from the target VM, address: '127.0.0.1:37853', transport: 'socket'
idk this is telling me that
dan1st
dan1st4d ago
it sais "UP-TO-DATE" because a previous compilation already compiled it I think gradle clean bootJar would probably fail
Hype_the_Time
Hype_the_TimeOP4d ago
oh i cleaned since
Hype_the_Time
Hype_the_TimeOP4d ago
18:25:03: Executing 'clean'…
Task :annotation-proccessor:clean Task :main:clean
BUILD SUCCESSFUL in 161ms 2 actionable tasks: 2 executed 18:25:03: Execution finished 'clean'.
dan1st
dan1st4d ago
then I can't tell you but I guess Gradle does something in a different way
Hype_the_Time
Hype_the_TimeOP4d ago
its CompilationUnit cu = StaticJavaParser.parse(new File(Paths.get("src/main/java", filePath).toString())); for some reason it doesnt throw an error in bootjar maybe its the dir (work dir) nope both same base path it seems working directory.... /home/spieler/IdeaProjects/BBsentials-Server/main vs /home/spieler/IdeaProjects/BBsentials-Server question is how do i fix this (without setting a set path which i want to avoid)
dan1st
dan1st4d ago
ah I think it isn't actually whether you execute bootJar or compileJava that doesn't make a difference but it makes a difference on where Gradle is run/whether you run gradle for the whole project or just for the main module essentially you can fix it like this: Never rely on the working directory in an annotation processor
Hype_the_Time
Hype_the_TimeOP4d ago
how then?
dan1st
dan1st4d ago
Filer (Java SE 21 & JDK 21)
declaration: module: java.compiler, package: javax.annotation.processing, interface: Filer
dan1st
dan1st4d ago
or similar
processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "your.package.name.here", "YourClassName.java")
processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "your.package.name.here", "YourClassName.java")
I think
Hype_the_Time
Hype_the_TimeOP4d ago
ill write a method
dan1st
dan1st4d ago
What is StaticJavaParser? That gives you a FileObject - if you really need to use File, you can do new File(yourFileObject.toUri()) I think
Hype_the_Time
Hype_the_TimeOP4d ago
its basically something where you can get methods source code etc
dan1st
dan1st4d ago
yeah but can you show the method there? Did you write that?
Hype_the_Time
Hype_the_TimeOP4d ago
i need it to clone a getters static value
dan1st
dan1st4d ago
?
Hype_the_Time
Hype_the_TimeOP4d ago
wdym
dan1st
dan1st4d ago
StaticJavaParser is a class that has methods, right? Can you show the signatures of these methods?
Hype_the_Time
Hype_the_TimeOP4d ago
No description
dan1st
dan1st4d ago
ok then you can do
FileObject sourceFile = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "your.package.name.here", "YourClassName.java");
CompilationUnit cu;
try(InputStream is = new BufferedInputStream(sourceFile.openInputStream())){
cu = yourStaticJavaParser.parse(is);
}
FileObject sourceFile = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "your.package.name.here", "YourClassName.java");
CompilationUnit cu;
try(InputStream is = new BufferedInputStream(sourceFile.openInputStream())){
cu = yourStaticJavaParser.parse(is);
}
Maxxx005
Maxxx0054d ago
private CompilationUnit getSourceCU(ProcessingEnvironment processingEnv, TypeElement typeElement) {
try (InputStream inputStream = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName()).openInputStream()) {
return StaticJavaParser.parse(inputStream);
} catch (IOException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to parse source file: " + e.getMessage(), typeElement);
throw new RuntimeException(e);
}
}
private CompilationUnit getSourceCU(ProcessingEnvironment processingEnv, TypeElement typeElement) {
try (InputStream inputStream = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName()).openInputStream()) {
return StaticJavaParser.parse(inputStream);
} catch (IOException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to parse source file: " + e.getMessage(), typeElement);
throw new RuntimeException(e);
}
}
This message has been formatted automatically. You can disable this using /preferences.
dan1st
dan1st4d ago
yes, looks good though idk whether you need the .java
Hype_the_Time
Hype_the_TimeOP4d ago
/home/spieler/IdeaProjects/BBsentials-Server/main/src/main/java/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java:17: Fehler: Failed to parse source file: de.hype.bbsentials.server.discord.events.staticimplementations.commands.commands.development/TestDiscordCommand.java public class TestDiscordCommand extends AbstractSingleCommand { ^
Maxxx005
Maxxx0054d ago
private CompilationUnit getSourceCU(ProcessingEnvironment processingEnv, TypeElement typeElement) {
try (InputStream inputStream = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName()+".java").openInputStream()) {
return StaticJavaParser.parse(inputStream);
} catch (IOException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to parse source file: " + e.getMessage(), typeElement);
throw new RuntimeException(e);
}
}
private CompilationUnit getSourceCU(ProcessingEnvironment processingEnv, TypeElement typeElement) {
try (InputStream inputStream = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName()+".java").openInputStream()) {
return StaticJavaParser.parse(inputStream);
} catch (IOException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to parse source file: " + e.getMessage(), typeElement);
throw new RuntimeException(e);
}
}
This message has been formatted automatically. You can disable this using /preferences.
Hype_the_Time
Hype_the_TimeOP4d ago
probably replace dots with /?
dan1st
dan1st4d ago
possible but I don't think so Are you using JPMS modules? i.e. do you have module-info.java files?
Hype_the_Time
Hype_the_TimeOP4d ago
no clue what that is → doubt it
dan1st
dan1st4d ago
Is there a module-info.java file in any of the src folders?
Hype_the_Time
Hype_the_TimeOP4d ago
nope
dan1st
dan1st4d ago
ig try with slashes instead of the dots also consider including the exception class name in the error message Also does getResource() return anything?
Hype_the_Time
Hype_the_TimeOP4d ago
Method threw 'javax.annotation.processing.FilerException' exception. Module specified but the location is neither a module-oriented location, nor a multi-module output location.
Maxxx005
Maxxx0054d ago
private CompilationUnit getSourceCU(ProcessingEnvironment processingEnv, TypeElement typeElement) {
FileObject sourceFile = null;
try {
sourceFile = processingEnv.getFiler().getResource(StandardLocation.CLASS_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString().replace(".","/"), typeElement.getSimpleName() + ".java");
CompilationUnit cu;
try (InputStream is = new BufferedInputStream(sourceFile.openInputStream())) {
return StaticJavaParser.parse(is);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private CompilationUnit getSourceCU(ProcessingEnvironment processingEnv, TypeElement typeElement) {
FileObject sourceFile = null;
try {
sourceFile = processingEnv.getFiler().getResource(StandardLocation.CLASS_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString().replace(".","/"), typeElement.getSimpleName() + ".java");
CompilationUnit cu;
try (InputStream is = new BufferedInputStream(sourceFile.openInputStream())) {
return StaticJavaParser.parse(is);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
This message has been formatted automatically. You can disable this using /preferences.
dan1st
dan1st4d ago
?
Hype_the_Time
Hype_the_TimeOP4d ago
error message
dan1st
dan1st4d ago
is that the error with replacing dots by slashes? ok yeah you shouldn't replace dots with slashes you could try without the .java
Hype_the_Time
Hype_the_TimeOP4d ago
Method threw 'java.io.FileNotFoundException' exception. de.hype.bbsentials.server.discord.events.staticimplementations.commands.commands.development/TestDiscordCommand.java without .java the same but -.java i might have fouind it nvm
Hype_the_Time
Hype_the_TimeOP4d ago
sourceFile = processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName())
No description
dan1st
dan1st4d ago
ok seems good so far
Hype_the_Time
Hype_the_TimeOP4d ago
but later part still throws an error
dan1st
dan1st4d ago
does openInputStream() fail on that? which part exactly?
Hype_the_Time
Hype_the_TimeOP4d ago
sourceFile.openInputStream()
dan1st
dan1st4d ago
Can you call getUri()?
Hype_the_Time
Hype_the_TimeOP4d ago
sorucefile does not have that method it has toUri() file:///home/spieler/IdeaProjects/BBsentials-Server/main/build/generated/sources/annotationProcessor/java/main/de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand
dan1st
dan1st4d ago
FileObject try using that on the File constructor so new File(sourceFile.toUri())
Hype_the_Time
Hype_the_TimeOP4d ago
new File(sourceFile.toUri()).exists() → false
dan1st
dan1st4d ago
What is new File(sourceFile.toUri())?
Hype_the_Time
Hype_the_TimeOP4d ago
doesnt throw an error
dan1st
dan1st4d ago
oh so that has no .java at the end? Does it have a .java?
Hype_the_Time
Hype_the_TimeOP4d ago
no
dan1st
dan1st4d ago
you could do a bit of a workaround you get the File you call getParentFile() on it
Hype_the_Time
Hype_the_TimeOP4d ago
new File((sourceFile.toUri().toURL().toString()+".java").replace("file:","")).exists() → false
dan1st
dan1st4d ago
and then you get the right file with new File(parent, className+".java")
File fileWithoutExtension = new File(sourceFile);
File sourceFileDir = fileWithoutExtension.getParentFile();
File sourceFile = new File(sourceFileDir, typeElement.getSimpleName());
File fileWithoutExtension = new File(sourceFile);
File sourceFileDir = fileWithoutExtension.getParentFile();
File sourceFile = new File(sourceFileDir, typeElement.getSimpleName());
Hype_the_Time
Hype_the_TimeOP4d ago
new File(sourceFile.toUri()).getParentFile().listFiles() → null
dan1st
dan1st4d ago
you used SOURCE_OUTPUT here that's the wrong one it should be SOURCE_PATH
Hype_the_Time
Hype_the_TimeOP4d ago
Method threw 'java.io.FileNotFoundException' exception.
dan1st
dan1st4d ago
Which method?
Hype_the_Time
Hype_the_TimeOP4d ago
(sourceFile = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName()))
dan1st
dan1st4d ago
you might need the .java there
Hype_the_Time
Hype_the_TimeOP4d ago
sourceFile = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName()+".java") → same error
dan1st
dan1st4d ago
oh try that:
processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "", processingEnv.getElementUtils().getPackageOf(typeElement).toString().replace('.','/')+"/"+typeElement.getSimpleName()+".java")
processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, "", processingEnv.getElementUtils().getPackageOf(typeElement).toString().replace('.','/')+"/"+typeElement.getSimpleName()+".java")
Hype_the_Time
Hype_the_TimeOP4d ago
still thows tried null in middle
dan1st
dan1st4d ago
which call throws what exactly?
Hype_the_Time
Hype_the_TimeOP4d ago
(to check whether it got executed for sure) should be the filer with getresource de/hype/bbsentials/server/discord/events/staticimplementations/commands/commands/development/TestDiscordCommand.java
dan1st
dan1st4d ago
and the first argument is the empty string? Can you try that?
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);

Iterable<? extends File> locations = fm.getLocation(StandardLocation.SOURCE_PATH);
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);

Iterable<? extends File> locations = fm.getLocation(StandardLocation.SOURCE_PATH);
Hype_the_Time
Hype_the_TimeOP4d ago
can you make it a 1 liner so i can evaluate in intelij?
dan1st
dan1st4d ago
then iterate over locations and get the contents I can try
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH).forEach(System.out::println)
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH).forEach(System.out::println)
then it should print the stuff to System.out
Hype_the_Time
Hype_the_TimeOP4d ago
doesnt work. try processingEnv.getMessager().printError(message) instead of sout
dan1st
dan1st4d ago
or
StreamSupport.stream(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH).forEach(System.out::println).spliterator(), false).map(Object::toString).join(Collectors.joining(" | "))
StreamSupport.stream(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH).forEach(System.out::println).spliterator(), false).map(Object::toString).join(Collectors.joining(" | "))
that would be
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH).forEach(processingEnv.getMessager()::printError)
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH).forEach(processingEnv.getMessager()::printError)
Hype_the_Time
Hype_the_TimeOP4d ago
java.lang.NullPointerException also had to change it since the code you provided was wrong (not executable): StreamSupport.stream(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH).spliterator(), false).map(Object::toString).collect(Collectors.joining(" | "))
dan1st
dan1st4d ago
or just
StreamSupport.stream(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH).spliterator(), false).toList())
StreamSupport.stream(ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH).spliterator(), false).toList())
Hype_the_Time
Hype_the_TimeOP4d ago
java.lang.NullPointerException
dan1st
dan1st4d ago
yeah I forgot to remove the forEach where? the getStandardFileManager?
Hype_the_Time
Hype_the_TimeOP4d ago
nope that alone is valid thats the problem in evaluating like this. you have no clue which part thgrows the error
dan1st
dan1st4d ago
getLocation?
Hype_the_Time
Hype_the_TimeOP4d ago
yeah thats null ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH)
dan1st
dan1st4d ago
you could in principle try to access some resource or another thing and then get to the path that way
Hype_the_Time
Hype_the_TimeOP4d ago
in which way?
dan1st
dan1st4d ago
Do you have any known resource file in your project? actually it's probably not a good idea either
Hype_the_Time
Hype_the_TimeOP4d ago
i mean i do robots.txt for example also diff idea what if i check the work dir if it ends with /main or sth and if not i append it?
dan1st
dan1st4d ago
it would't be that great because it would give you the output directory
Hype_the_Time
Hype_the_TimeOP4d ago
regarding message above?
dan1st
dan1st4d ago
Trees trees = Trees.instance(processingEnv);
trees.getPath(yourTypeElement);
Trees trees = Trees.instance(processingEnv);
trees.getPath(yourTypeElement);
dan1st
dan1st4d ago
Trees (Java SE 21 & JDK 21)
declaration: module: jdk.compiler, package: com.sun.source.util, class: Trees
dan1st
dan1st4d ago
What information do you actually need from the source file? actually yes
Hype_the_Time
Hype_the_TimeOP4d ago
i have a getter which always returns the same value in my code that i use to duplciate it
dan1st
dan1st4d ago
Trees.instance(processingEnv).getPath(yourElement).getCompilationUnit().getSourceFile()
Trees.instance(processingEnv).getPath(yourElement).getCompilationUnit().getSourceFile()
try that
dan1st
dan1st4d ago
Trees (Java SE 21 & JDK 21)
declaration: module: jdk.compiler, package: com.sun.source.util, class: Trees
dan1st
dan1st4d ago
but this will make your annotation processor only work with javac
Hype_the_Time
Hype_the_TimeOP4d ago
wdym no gralde or what?
dan1st
dan1st4d ago
Gradle uses javac by default but EJC probably doesn't like it and if you are trying to access Kotlin classes, it would probably not work either
Hype_the_Time
Hype_the_TimeOP4d ago
that would probably need a diff parser either anyway
dan1st
dan1st4d ago
?
Hype_the_Time
Hype_the_TimeOP4d ago
(kotlin) BUILD SUCCESSFUL in 28s think thats all tyvm for your time (and patience) 1 ½ hours
dan1st
dan1st4d ago
that's how it works with annotation processors
Hype_the_Time
Hype_the_TimeOP4d ago
just tested whether hotswap works
dan1st
dan1st4d ago
During that time, I crashed @JavaBot multiple times
Hype_the_Time
Hype_the_TimeOP4d ago
yes it does wdym syntax or sth
dan1st
dan1st4d ago
no I did stuff on the server the bot is running on
Hype_the_Time
Hype_the_TimeOP4d ago
ah so thats why long reponse times fine by me tho
dan1st
dan1st4d ago
sometimes that was also me googling how to access sources with annotation processors or sth like that
Hype_the_Time
Hype_the_TimeOP4d ago
i wouldnt have a right to complain anyway. youre doing this volunatirly also @dan1st make sth so you can disable This message has been formatted automatically. You can disable this using /preferences.
dan1st
dan1st4d ago
You mean - something like a preference?
No description
dan1st
dan1st4d ago
You can disable this using /preferences
Hype_the_Time
Hype_the_TimeOP4d ago
no i want auto formmatting just not the emebd below
dan1st
dan1st4d ago
just use a codeblock yourself? the auto formatting thing is supposed to help with people who don't understand codeblocks
Hype_the_Time
Hype_the_TimeOP4d ago
i mean ig possible but its convenient if you dont have to
dan1st
dan1st4d ago
ig we could add it
Hype_the_Time
Hype_the_TimeOP4d ago
but the use prefnces to disable this message is a bit ugly
dan1st
dan1st4d ago
the thing is that the autoformatting isn't perfect like there may be code outside formatted parts but yeah ig it shouldn't be much of an issue to implement
Hype_the_Time
Hype_the_TimeOP4d ago
theres like no way to make it perfect. maybe it would be an upgrade to use an ai or sth for it but uhm sounds resource intensive at minimum
dan1st
dan1st4d ago
no I don't want to have the actual content changed
Hype_the_Time
Hype_the_TimeOP4d ago
maybe if you ask for line changes and then change lines yourself but ye
dan1st
dan1st4d ago
nah, not worth it people should just use codeblocks at that point
JavaBot
JavaBot4d ago
Post Closed
This post has been closed by <@595201583923331082>.

Did you find this page helpful?