Java – sonar flag “bad practice”: if the class is extended, it may not be safe to use getresource in XYZ
•
Java
Sonar pointed out this error in our java project Welcome any suggestions on safe programming!
URL url = getClass().getResource("/myWonderfulResource.txt"); if (url == null) { throw new IllegalStateException("File not found: /myWonderfulResource.txt"); }
Solution
Make the course final, so it cannot be expanded The warning is to prevent extension classes from (possibly) trying to use resources that do not exist
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码