question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When loading the following C code with the cpg, I get an Exception:

int main() {
	size_t count = (size_t)(42);
	return 0;
}
java.lang.ClassCastException: class 
org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTUnaryExpression cannot be cast to class 
org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression

Whereas the following code can be loaded successfully:

int main() {
	size_t count = (size_t)42;
	return 0;
}

I’m using the cpg and cpg-neo4j from master branch. Can you reproduce the error?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
Masrepuscommented, Jul 14, 2021

If A is a function pointer, (A)(B) can very well be a call. It’s not more or less unusual to write a call that way than writing a cast like that

1reaction
pecktocommented, Jul 14, 2021

Thanks for the fix! Works for me. Yes, the intention was a cast. With includes enabled, the cpg is doing this correctly in both situations. But without the include, we have encountered a C language ambiguity ^^ Interpreting (A)(B) as a function call A(B) seems to me like an unusual coding style. Changing the heuristic to interpret this as a cast would be a better fit in my opinion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Explanation of ClassCastException in Java - Stack Overflow
A class cast exception is thrown by Java when you try to cast an Object of one data type to another.
Read more >
How to Solve Class Cast Exceptions in Java? - GeeksforGeeks
1. Checked Exception: The exception which is checked by the compiler for the smooth execution of the program at runtime is called a...
Read more >
How to Solve ClassCastException in Java - Rollbar
It is a runtime exception that occurs when the application code attempts to cast an object to another class of which the original...
Read more >
ClassCastException (Java Platform SE 7 ) - Oracle Help Center
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For...
Read more >
How to fix java.lang.classcastexception - Net-Informations.Com
classcastexception occurs when you try to cast an instance of an Object to a type that it is not. Casting only works when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found