Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheckStyle failed for Invalid field access : length #517

Closed
ExtinctStars opened this issue Dec 20, 2022 · 9 comments
Closed

CheckStyle failed for Invalid field access : length #517

ExtinctStars opened this issue Dec 20, 2022 · 9 comments

Comments

@ExtinctStars
Copy link

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 <BaseReporter.hx> is <for (related in message.related)>, how could this invoke ().length fuction? I am confused.

@ExtinctStars
Copy link
Author

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
Copy link
Member

cmd gives me these error msgs. line 114 in <BaseReporter.hx> 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
Copy link
Author

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
Copy link
Member

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 added a commit to AlexHaxe/haxe-checkstyle that referenced this issue Jan 4, 2023
@AlexHaxe
Copy link
Member

AlexHaxe commented Jan 4, 2023

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
Copy link
Author

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
Copy link
Member

AlexHaxe commented Jan 9, 2023

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

@ExtinctStars
Copy link
Author

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants