HaxeCheckstyle / haxe-checkstyle

Haxe Checkstyle
http://haxecheckstyle.github.io/docs
MIT License
124 stars 27 forks source link

CheckStyle failed for Invalid field access : length #517

Closed ExtinctStars closed 1 year ago

ExtinctStars commented 1 year ago

Invalid field access : length

Called from checkstyle/reporter/BaseReporter.hx line 114 Called from checkstyle/reporter/XMLReporter.hx line 120 Called from checkstyle/reporter/XMLReporter.hx line 58 Called from checkstyle/reporter/XMLReporter.hx line 45 Called from checkstyle/reporter/ReporterManager.hx line 44 Called from checkstyle/Main.hx line 225 Called from checkstyle/Main.hx line 134 Called from checkstyle/Main.hx line 121 Called from checkstyle/Main.hx line 318

cmd gives me these error msgs. line 114 in is <for (related in message.related)>, how could this invoke ().length fuction? I am confused.

ExtinctStars commented 1 year ago

My cmd line is: haxelib run checkstyle -s xxx.hx -c xxx\mycheckstyle.json -r xml -p xxx\report.xml --show-parser-errors

When I delete the <--show-parser-errors> arg, the error msgs didn't show up and the program ran normally.

AlexHaxe commented 1 year ago

cmd gives me these error msgs. line 114 in is <for (related in message.related)>, how could this invoke ().length fuction? I am confused.

well, do run a loop over an array someone has to read it's length to see if you're done iterating.

I can see it running in a null pointer exception, when related field is not initialised, and since it's optional there is a possibility it could be null but I haven't found a scenario where it did happen. does it crash for all of your files or is it specific ones? can you share a file where it crashes (or point me to a github repository with files that crash)?

ExtinctStars commented 1 year ago

It crash for a specific file and I am sorry that I cannot offer you the file content because our code was not open-sourced.

When I turn on --show-parser-errors, it will call < addError() > then call this line < reporter.addMessage(getErrorMessage(e, f.name, "Check " + name)); > but the message.related return from getErrorMessage() was null. So this message will cause the nullpointer exception. Am I wrong about this?

AlexHaxe commented 1 year ago

alright, I see where the problem lies. fix incoming.

nevertheless I am interested in what causes parsing to fail. can you reduce your file to a point where you can share it (while it still fails parsing)? e.g. throwing out everything that doesn't cause parser errors and replacing every name or otherwise incriminating information with something harmless.

AlexHaxe commented 1 year ago

should be fixed in checkstyle 2.8.4. still I want to take a look at that "broken" file, to attempt fixing the actual parser error. because with a parser error your file will remain unchecked. so if you find the time please post a version that is shareable.

ExtinctStars commented 1 year ago

TestLink.txt I have attached the corresponding file, and when I update checkstyle to the latest version and use --show-parser-errors, it shows this error msg: Checker - Error: Check makeAST [] failed: Unexpected @

AlexHaxe commented 1 year ago

are you using a macro to handle stuff like xml.@baseType? because that doesn't look like valid Haxe code to me.

ExtinctStars commented 1 year ago

To be honest, I have no idea what that is. It seems like a file with history, and I can not find anywhere defines a type XML. Maybe we don't even use these codes now. You can just ignore this question. -_-|||

AlexHaxe commented 1 year ago

well since it is an error during makeAST which means haxeparser's Parser fails to come up with an AST for your file, I don't think there is anything that can be done with that syntax. so maybe just delete the file and see if your project still compiles and works?! :)

anyway thanks for reporting an issue and your help identifying the underlying problem