GeezerVison is showing github.com — [go] Error parsing unicode values · Issue #2752 · pmd/pmd
[go] Error parsing unicode values #2752
Labels
a:bugPMD crashes or fails to analyse a file.in:cpdAffects the copy-paste detectorin:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception Description
Affects PMD Version: 6.26.0
Description:
CPD crashing on following file, didn't expect that. Maybe related to #2605 ?
Exception Stacktrace:
net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file /tmp/goIsAmazing-master/goBasis/src/fundation/5. sliceOperation/sliceOperation6.go at line 20, column 12. Encountered: token recognition error at: ''??'
at net.sourceforge.pmd.cpd.AntlrTokenizer.tokenize(AntlrTokenizer.java:44)
at net.sourceforge.pmd.cpd.CPD.addAndThrowLexicalError(CPD.java:144)
at net.sourceforge.pmd.cpd.CPD.add(CPD.java:139)
at net.sourceforge.pmd.cpd.CPD.add(CPD.java:108)
at net.sourceforge.pmd.cpd.CPD.add(CPD.java:70)
at net.sourceforge.pmd.cpd.CPD.addDirectory(CPD.java:80)
at net.sourceforge.pmd.cpd.CPD.addRecursively(CPD.java:65)
at net.sourceforge.pmd.cpd.CPDCommandLineInterface.addSourcesFilesToCPD(CPDCommandLineInterface.java:134)
at net.sourceforge.pmd.cpd.CPDCommandLineInterface.addSourceFilesToCPD(CPDCommandLineInterface.java:114)
at net.sourceforge.pmd.cpd.CPDCommandLineInterface.main(CPDCommandLineInterface.java:87)
at net.sourceforge.pmd.cpd.CPD.main(CPD.java:179)
Caused by: LexerNoViableAltException(''')
at org.antlr.v4.runtime.atn.LexerATNSimulator.failOrAccept(LexerATNSimulator.java:312)
at org.antlr.v4.runtime.atn.LexerATNSimulator.execATN(LexerATNSimulator.java:233)
at org.antlr.v4.runtime.atn.LexerATNSimulator.match(LexerATNSimulator.java:117)
at org.antlr.v4.runtime.Lexer.nextToken(Lexer.java:141)
at net.sourceforge.pmd.lang.go.antlr4.GolangLexer.nextToken(GolangLexer.java:126)
at net.sourceforge.pmd.lang.antlr.AntlrTokenManager.getNextTokenFromAnyChannel(AntlrTokenManager.java:47)
at net.sourceforge.pmd.lang.antlr.AntlrTokenManager.getNextToken(AntlrTokenManager.java:40)
at net.sourceforge.pmd.cpd.token.internal.BaseTokenFilter.getNextToken(BaseTokenFilter.java:45)
at net.sourceforge.pmd.cpd.AntlrTokenizer.tokenize(AntlrTokenizer.java:39)
... 10 more
Code Sample demonstrating the issue:
https://github.com/SuperSupeng/goIsAmazing/blob/0fef5154b97dd170144254596c46d5892454c928/goBasis/src/fundation/5.%20sliceOperation/sliceOperation6.go#L20:
package main
import "fmt"
func main() {
//string底层是一个byte数组,因此string也可以进行切片操作
str := "hello world"//string是不可变的
slice := str[4:]
fmt.Println(slice)
//若要对string进行修改需要将string修改为byte或rune的切片在操作
//但是转为byte无法进行中文操作
bytes := []byte(str)
bytes[2] = 'x'
str = string(bytes)
fmt.Println(str)
//转换成rune可以对中文进行操作
runes := []rune(str)
runes[0] = '哈'
str = string(runes)
fmt.Println(str)
}
Steps to reproduce:
Clone linked repository and run cpd: ./run.sh cpd --files . --language go --minimum-tokens 50
Running PMD through: CLI
Activity
added a commit that references this issue
on May 1, 2022This issue will close once commit 669f2fe is merged into the 'main' branch.669f2fe changed the title
[-][Go] Error parsing unicode values[/-] [+][go] Error parsing unicode values[/+] on May 20, 2022
Metadata
Metadata
a:bugPMD crashes or fails to analyse a file.in:cpdAffects the copy-paste detectorin:grammarAbout the grammar of a lexer or parser, eg, a parse/lex exception Development
No branches or pull requestsIssue actions