openhab / static-code-analysis

Maven tooling for static code analysis
https://www.openhab.org/
Other
32 stars 21 forks source link

ForbiddenPackageUsageCheck error #353

Closed tmrobert8 closed 4 years ago

tmrobert8 commented 5 years ago

There is definitely something wrong with the ForbiddenPackageUsageCheck check. Seems like it get's 'stuck' marking the error on every class following the one that created it.

Here's an example of the incorrect check (the constants class of course only has constants and none of common collect classes)


org.openhab.binding.sony.internal.SonyBindingConstants.java
--

checkstyle | 2 | 22 | style | ForbiddenPackageUsageCheck | The package com.google.common.collect.BiMap should not be used.
checkstyle | 2 | 23 | style | ForbiddenPackageUsageCheck | The package com.google.common.collect.HashBiMap should not be used.
checkstyle | 2 | 49 | style | ForbiddenPackageUsageCheck | The package com.google.common.cache.Cache should not be used.
checkstyle | 2 | 50 | style | ForbiddenPackageUsageCheck | The package com.google.common.cache.CacheBuilder should not be used.
checkstyle | 2 | 51 | style | ForbiddenPackageUsageCheck | The package com.google.common.cache.RemovalListener should not be used.
checkstyle | 2 | 52 | style | ForbiddenPackageUsageCheck | The package com.google.common.cache.RemovalNotification should not be used.
martinvw commented 5 years ago

Indeed, I suppose that this method:

https://github.com/openhab/static-code-analysis/blob/6e631de725f58f4fd2b6fa5fc98bd73b38b7ec42/custom-checks/checkstyle/src/main/java/org/openhab/tools/analysis/checkstyle/ForbiddenPackageUsageCheck.java#L79-L84

requires also some reset of the importsToLineNumbers in the end.

martinvw commented 5 years ago

If anyone want to pick this up, he/she is more than welcome. Its relatively easy and isolated and the code has some existing tests but of course misses one for this case.

wborn commented 4 years ago

Fixed by #362