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
⌛
This post has been reserved for your question.
Hey @Hype_the_Time! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
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
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
Can you run
gradle compileJava
?
For example there's TestDiscordCommand
- does that one exist?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 leastAre you using Kotlin in that project?
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
so the sources are in src/main?
Does the error also occur with that command or not?
i devided anjnotation processor and the main project in 2 sub projects
yes it occurs
Where did you specify you are using src/main instead of src/main/java?
Gradle uses src/main/java unless you configured it differently
Is that the source folder?
But I asked about how you specified it
not how IntelliJ displays it
seems like you are using src/main/java
in the sub project
there's a difference between source folders and modules
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
What is the full path of
TestDiscordCommand.java
?.
and that file exists there?
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")
}
shouldn't make a difference if compilation fails
What happens when commenting all Kotlin stuff in the build.gradle files?
still fails
Can you run the following command in a terminal?
my fault
thats not a command no?
copied too much
just file?
or
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
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)?
Can you use the command line and not IntelliJ for it?
ig
or close IntellIJ and then run it maybe
btw you might need to do
./gradlew compileJava
or similar
to use Gradle from your project$ ./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
oh, that's a different error
seems like you aren't using JDK 21
Do you have JDK 21 on your system?
linux java package is 17
i have downloaded the othger and set paths for it but thats intelij not gradlew or sth probably
Where is the other one installed?
cusom path somewhere in user home i think
so you can tell Gradle to use that one by setting the JAVA_HOME
so
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?
you can
idk where your JDK is
maybe in
/home/spieler/.jdks
?yes
Did you find it
export JAVA_HOME=~/.jdks/jbr_jcef-21.0.3-linux-x64-b509.4/
FYI
gradle build
includes gradle compileJava
(normally)
and then run the gradle command in the same terminalspieler@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 FAILEDHinweis: 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
oh wait these come from the annotation processor
my first though too but no
these are used but not generated by it
Why not?
yeah but the error comes from the annotation processor
Can you attach a debugger to the annotation processor?
yeah but they arent generated by it
so?
they are used but no generated
if the annotation processor wants to use something but has an issue with it, it still fails
where do you want me to attach it?
WAIT
i have an idea
Can you run
./gradlew build --no-daemon -Dorg.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
?CompilationUnit cu = StaticJavaParser.parse(new File(Paths.get("src/main/java", filePath).toString()));
and then create a "Remote Debugging" run configuration
ive got it attached just no clue where to where put its breakpoint
in the
process()
methodi remebered the thing how to atatch last time you explained
yeah that sounds like causing issues like that
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
idk
but maybe it runs javac differently
or rather why is bootjar not
sure about that?
normally you shouldn't even be able to run bootjar without compileJava
idk this is telling me that
it sais "UP-TO-DATE" because a previous compilation already compiled it
I think
gradle clean bootJar
would probably failoh i cleaned since
18:25:03: Executing 'clean'…
Task :annotation-proccessor:clean Task :main:cleanBUILD SUCCESSFUL in 161ms 2 actionable tasks: 2 executed 18:25:03: Execution finished 'clean'.
then I can't tell you but I guess Gradle does something in a different way
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)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
how then?
Try using
processingEnv.getFiler().getResource()
to access source files: https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/annotation/processing/Filer.html#getResource(javax.tools.JavaFileManager.Location,java.lang.CharSequence,java.lang.CharSequence)Filer (Java SE 21 & JDK 21)
declaration: module: java.compiler, package: javax.annotation.processing, interface: Filer
or similar
I think
ill write a method
What is
StaticJavaParser
?
That gives you a FileObject
- if you really need to use File
, you can do new File(yourFileObject.toUri())
I thinkits basically something where you can get methods source code etc
yeah but can you show the method there?
Did you write that?
i need it to clone a getters static value
?
wdym
StaticJavaParser
is a class that has methods, right?
Can you show the signatures of these methods?ok then you can do
This message has been formatted automatically. You can disable this using
/preferences
.yes, looks good
though idk whether you need the
.java
/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 {
^
This message has been formatted automatically. You can disable this using
/preferences
.probably replace dots with /?
possible but I don't think so
Are you using JPMS modules?
i.e. do you have module-info.java files?
no clue what that is
→ doubt it
Is there a module-info.java file in any of the src folders?
nope
ig try with slashes instead of the dots
also consider including the exception class name in the error message
Also does
getResource()
return anything?Method threw 'javax.annotation.processing.FilerException' exception.
Module specified but the location is neither a module-oriented location, nor a multi-module output location.
This message has been formatted automatically. You can disable this using
/preferences
.?
error message
is that the error with replacing dots by slashes?
ok yeah you shouldn't replace dots with slashes
you could try without the
.java
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
sourceFile = processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName())
ok
seems good so far
but later part still throws an error
does
openInputStream()
fail on that?
which part exactly?sourceFile.openInputStream()
Can you call
getUri()
?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
FileObject
try using that on the File
constructor
so new File(sourceFile.toUri())
new File(sourceFile.toUri()).exists() → false
What is
new File(sourceFile.toUri())
?doesnt throw an error
oh so that has no
.java
at the end?
Does it have a .java
?no
you could do a bit of a workaround
you get the
File
you call getParentFile()
on itnew File((sourceFile.toUri().toURL().toString()+".java").replace("file:","")).exists() → false
and then you get the right file with
new File(parent, className+".java")
new File(sourceFile.toUri()).getParentFile().listFiles() → null
you used SOURCE_OUTPUT here
that's the wrong one
it should be
SOURCE_PATH
Method threw 'java.io.FileNotFoundException' exception.
Which method?
(
sourceFile = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName())
)you might need the .java there
sourceFile = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, processingEnv.getElementUtils().getPackageOf(typeElement).toString(), typeElement.getSimpleName()+".java") → same error
oh
try that:
still thows
tried null in middle
which call throws what exactly?
(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
and the first argument is the empty string?
Can you try that?
can you make it a 1 liner so i can evaluate in intelij?
then iterate over
locations
and get the contents
I can try
then it should print the stuff to System.out
doesnt work. try processingEnv.getMessager().printError(message)
instead of sout
or
that would be
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(" | "))
or just
java.lang.NullPointerException
yeah I forgot to remove the forEach
where?
the
getStandardFileManager
?nope that alone is valid
thats the problem in evaluating like this. you have no clue which part thgrows the error
getLocation
?yeah thats null
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null).getLocation(StandardLocation.SOURCE_PATH)
you could in principle try to access some resource or another thing
and then get to the path that way
in which way?
Do you have any known resource file in your project?
actually it's probably not a good idea either
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?
it would't be that great because it would give you the output directory
regarding message above?
you could also try something withz that: https://docs.oracle.com/en/java/javase/21/docs/api/jdk.compiler/com/sun/source/util/Trees.html
Trees (Java SE 21 & JDK 21)
declaration: module: jdk.compiler, package: com.sun.source.util, class: Trees
What information do you actually need from the source file?
actually yes
i have a getter which always returns the same value in my code that i use to duplciate it
try that
Trees
is https://docs.oracle.com/en/java/javase/21/docs/api/jdk.compiler/com/sun/source/util/Trees.htmlTrees (Java SE 21 & JDK 21)
declaration: module: jdk.compiler, package: com.sun.source.util, class: Trees
but this will make your annotation processor only work with javac
wdym no gralde or what?
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
that would probably need a diff parser either anyway
?
(kotlin)
BUILD SUCCESSFUL in 28s
think thats all
tyvm for your time (and patience)
1 ½ hours
that's how it works with annotation processors
just tested whether hotswap works
During that time, I crashed @JavaBot multiple times
yes it does
wdym
syntax or sth
no I did stuff on the server the bot is running on
ah so thats why long reponse times
fine by me tho
sometimes that was also me googling how to access sources with annotation processors or sth like that
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.
You mean - something like a preference?
You can disable this using /preferences
no i want auto formmatting
just not the emebd below
just use a codeblock yourself?
the auto formatting thing is supposed to help with people who don't understand codeblocks
i mean ig possible but its convenient if you dont have to
ig we could add it
but the use prefnces to disable this message
is a bit ugly
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
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
no I don't want to have the actual content changed
maybe if you ask for line changes and then change lines yourself but ye
nah, not worth it
people should just use codeblocks at that point
Post Closed
This post has been closed by <@595201583923331082>.