preface
Recently, I saw several open source Maven plug-ins that generate Yapi documents. The basic operation is to read the comments in Java code, sort them into corresponding JSON according to the format required by Yapi, and then push them to Yapi server. On a whim, I pulled an open source code library, and then encountered many problems in the process of use, This article talks about how the code parsing library Qbox handles parsing exceptions when parsing code
Open joint
Qbox code base address: https://github.com/paul-hammant/qdox
Exception information thrown
Caused by: com.thoughtworks.qdox.parser.ParseException: syntax error @[10,1] in file:/*****/A.java
at com.thoughtworks.qdox.parser.impl.Parser.yyerror (Parser.java:1963)
at com.thoughtworks.qdox.parser.impl.Parser.yyparse (Parser.java:2085)
at com.thoughtworks.qdox.parser.impl.Parser.parse (Parser.java:1944)
at com.thoughtworks.qdox.library.SourceLibrary.parse (SourceLibrary.java:232)
at com.thoughtworks.qdox.library.SourceLibrary.parse (SourceLibrary.java:209)
at com.thoughtworks.qdox.library.SourceLibrary.addSource (SourceLibrary.java:159)
at com.thoughtworks.qdox.library.SortedClassLibraryBuilder.addSource (SortedClassLibraryBuilder.java:174)
at com.thoughtworks.qdox.JavaProjectBuilder.addSource (JavaProjectBuilder.java:151)
at com.thoughtworks.qdox.JavaProjectBuilder$2.visitFile (JavaProjectBuilder.java:224)
at com.thoughtworks.qdox.directorywalker.DirectoryScanner.walk (DirectoryScanner.java:103)
at com.thoughtworks.qdox.directorywalker.DirectoryScanner.walk (DirectoryScanner.java:91)
at com.thoughtworks.qdox.directorywalker.DirectoryScanner.walk (DirectoryScanner.java:91)
at com.thoughtworks.qdox.directorywalker.DirectoryScanner.walk (DirectoryScanner.java:91)
at com.thoughtworks.qdox.directorywalker.DirectoryScanner.walk (DirectoryScanner.java:91)
at com.thoughtworks.qdox.directorywalker.DirectoryScanner.walk (DirectoryScanner.java:91)
at com.thoughtworks.qdox.directorywalker.DirectoryScanner.walk (DirectoryScanner.java:91)
at com.thoughtworks.qdox.directorywalker.DirectoryScanner.walk (DirectoryScanner.java:91)
at com.thoughtworks.qdox.directorywalker.DirectoryScanner.scan (DirectoryScanner.java:81)
at com.thoughtworks.qdox.JavaProjectBuilder.addSourceTree (JavaProjectBuilder.java:218)
at com.thoughtworks.qdox.JavaProjectBuilder.addSourceTree (JavaProjectBuilder.java:205)
Parse exception code file
//package com.example.test.proxy;
//
///**
// * MyClass
// *
// * @author you_name 2021-12-21 20:02
// */
//public class A {
//} // line 9 line 10 is blank line
Solution:
JavaProjectBuilder builder = new JavaProjectBuilder();
builder.setErrorHandler((e) -> log.warn(e.getMessage()));
Optimize it.
JavaProjectBuilder builder = new JavaProjectBuilder();
builder.setErrorHandler((e) -> {
if (e.getClass().isAssignableFrom(ParseException.class)) {
log.warn(e.getMessage());
return;
}
throw e;
});
Read More:
- [Solved] Docker-compose Start error: pyrsistent syntax error: invalid syntax
- [Solved] com.alibaba.fastjson.JSONException: syntax error, pos 1, json
- [Solved] ClickHouse Error: Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): fai
- [Solved] Syntax Error: Error: ENOENT: no such file or directory, scandir ‘D:\LeStoreD
- [Solved] Cause: org.postgresql.util.PSQLException: ERROR: syntax error at end of input
- [Solved] Frida-server Startup Error: syntax error: unexpected‘(‘
- [Solved] JAVA Operate Database Error: You have an error in your SQL syntax; Dao layer SQL statement error
- [Solved] PageHelper Error: syntax error, error in :‘it 1 LIMIT ? ‘
- How to Solve mybatis-plus Paging Plug-in PaginationInnerInterceptor error
- Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber
- [Solved] Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException
- Mybatis Error: Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.
- [Solved] mybatis Error: Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.
- Byte 1 of UTF-8 sequence of error creating document instance. And bytes is invalid
- [Solved] Mvel2 Error: java.lang.VerifyError method: getKnownEgressType signature
- JAVA: Controller exception handling
- [Solved] Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration
- [Solved] Java.lang.IllegalStateException: Type handler was null on parameter mapping for property ‘__frch_it
- [Solved] Springboot Error: Error creating bean with name ‘xxxController‘
- Build a mybatis and it will appear session.selectOne Method error