weixin_39923137
weixin_39923137
2020-12-26 19:58

XmlValidator adds markers but not add it to ValidationResult

Hi Iwao!

Just realized, that when I validate my mappers, it won't report any error, however, markers will be set. It is commented out, but don't know the reason:

https://github.com/harawata/mybatipse/blob/master/mybatipse/src/net/harawata/mybatipse/mybatis/XmlValidator.java#L433

It is necessary to do so? If I uncomment it, it will add the same marker (as I can see), and the error will be counted in the XML ValidationResult also.

Best regards,

-- Vazul

该提问来源于开源项目:mybatis/mybatipse

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • weixin_39957951 weixin_39957951 4月前

    Thank you for the feedback !

    If I, for example, specify an incorrect property name, a marker is set on the line and the error is reported in the Problem View.

    mybatipse 31

    If the error is not shown in the Problem View, please check the contents configuration of the Problem View and make sure 'MyBatis XML Problem' is selected. Or did you mean something different by 'it won't report any error' ?

    Reading the doc, using ValidatorMessage/ValidationResult should not affect the visibility of the problem.

    Regards, Iwao

    点赞 评论 复制链接分享
  • weixin_39923137 weixin_39923137 4月前

    Hi Iwao!

    Thanks for the response.

    What I have noticed, that when you do manual validation on the mapper xml file, the validation will result in no error, however, MyBatis problem markers will be set. I think that's because the validation message is not added to the validation result. I think, it should be better to use the ValidationResult. Maybe you choose to handle your own markers, because you call XmlValidator directly from MybatipseIncrementalBuilder. Maybe, ValidationFramework.getDefault().validate(..) can be used, which will set markers based on ValidationResult.

    And Validation Builder also doing so, and we have Validation Builder set on our projects (if you enable faceted project for a project with Utility Project facet, it will automatically set Validation Builder on that project).(another problem is in this case that mapper xml files in output directory will be validated also)

    As I can understand, MybatipseIncrementalBuilder is used to validate mapper xml files, when corresponding java files have been changed. But looking at the code, it will validate all mappers in every case, no matter what is changed. But there is a MybatipseResourceChangeListener, where you track java file changes. Here, the corresponding mapper xml can be found in MapperNamespaceCache, and maybe the mapper can be revalidated, in case when Validation Builder is also set up.

    Sorry for this long brainstorming, just wanted to clarify what happens under the hood, and what I think that should be good in conjunction with Validation Builder, manual validation and regarding revalidatiing mapper xml files upon corresponding mapper interface change.

    Best regards,

    -- Vazul

    点赞 评论 复制链接分享
  • weixin_39957951 weixin_39957951 4月前

    What I have noticed, that when you do manual validation on the mapper xml file, the validation will result in no error, however, MyBatis problem markers will be set.

    I still cannot reproduce (or do not understand) your problem. By 'manual validation', you mean 'right clicking the XML mapper file and choose Validate from the contextual menu', is that correct? On my environment, the error is reported in my Problem View as seen in the picture in my previous comment.

    I appreciate your suggestions, but I need to reproduce the problem before modifying the code. Please provide the exact steps to reproduce the problem, preferably on a clean workspace.

    Oh, and have you enabled the MyBatipse Nature as explained in the README ?

    As I can understand, MybatipseIncrementalBuilder is used to validate mapper xml files, when corresponding java files have been changed. But looking at the code, it will validate all mappers in every case, no matter what is changed. But there is a MybatipseResourceChangeListener, where you track java file changes. Here, the corresponding mapper xml can be found in MapperNamespaceCache, and maybe the mapper can be revalidated, in case when Validation Builder is also set up.

    Let me try to explain the difficulty. For example, when a domain class is changed, all the XML mappers referencing this domain object (or its subclasses) must be re-validated and I couldn't find a reasonable way to search those corresponding mappers. This is why MyBatipse validates all the XML mappers on each change.

    点赞 评论 复制链接分享
  • weixin_39923137 weixin_39923137 4月前

    Hi Iwao!

    Yes, manual validation is by right click and Validate. In my environment, the result will be displayed in a dialog box, and this dialog box will show no error, however, error markers are set. Not a big issue, just made me a little confused.

    Regarding the revalidation upon build event: I see now. The can be any change, not just in the mapper interface itself, but in the return types and method argument types as well, so yes, if you don't maintain a correct full map of java to mapper xml references, then this will work.

    Thanks for the answers, best regards,

    -- Vazul

    点赞 评论 复制链接分享
  • weixin_39957951 weixin_39957951 4月前

    Oh...the dialog! I didn't pay any attention to the dialog contents, sorry XD I'll follow your suggestion and see if it solves the problem. Thank you very much for the explanation!

    Regards, Iwao

    点赞 评论 复制链接分享
  • weixin_39957951 weixin_39957951 4月前

    I have released 1.0.12 which should fix the result dialog issue. Thanks again for your report!

    点赞 评论 复制链接分享

相关推荐