Skip to content

Conversation

@astubbs
Copy link

@astubbs astubbs commented Jul 29, 2021

You should not be able to pass in invalid code and get obscure errors like "index out of range" exceptions. I found one place for this but the code should be audited for it everywhere. Better to run slower and have excellent errors.

fixes #199

@gastaldi
Copy link
Member

Can you format the sources using the formatter in https://github.com/forge/core/blob/master/eclipse-code-formatter-profile.xml?

@astubbs
Copy link
Author

astubbs commented Jul 29, 2021

ok done, and replaced all the times I saw it in this file

@gastaldi
Copy link
Member

gastaldi commented Jul 30, 2021

Can we have a test that verifies this is working as proposed?

Also it would be nice if you could squash all commits from this PR

@astubbs
Copy link
Author

astubbs commented Oct 19, 2021

Interestingly, the source validator is failing all the code snippets from the test, if they don't have a trailing ;

List<Problem> problems = Roaster.validateSnippet(stub);

java.lang.IllegalArgumentException: 
Invalid method code. [Problem: 'Syntax error, insert ";" to complete ClassBodyDeclarations' at 1:57-57]
	at org.jboss.forge.roaster.model.impl.MethodImpl.getMethodSources(MethodImpl.java:144)
	at org.jboss.forge.roaster.model.impl.MethodImpl.<init>(MethodImpl.java:133)
	at org.jboss.forge.roaster.model.impl.AbstractJavaSourceMemberHolder.addMethod(AbstractJavaSourceMemberHolder.java:352)
	at org.jboss.forge.test.roaster.model.MethodSignatureTest.testMethodSignatureParams(MethodSignatureTest.java:38)

Previously the code was just calling JavaClassSource temp = (JavaClassSource) Roaster.parse(stub); without validation. Odd the validator requires trailing ';' 🤔 ...

Protect in one place for out of range.
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

Successfully merging this pull request may close these issues.

All user code input should be validated

2 participants