Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent use of beta classes from google guava library?

Tags:

java

guava

We have been using Google collections in the production for several months. We would like to start using guava for additional functions. However, I'm afraid to bring guava into our product stack b/c some developers may start to use 'beta' classes.

We have various unit-tests in our code but at this point, I prefer not to include 'beta' class b/c it is subject to change in the future.

Is there any easy way to do detect if the project includes any 'beta' guava classes?

like image 639
mjlee Avatar asked Dec 27 '10 15:12

mjlee


3 Answers

Overstock.com recently released a Findbugs plugin that flags usage of @Beta classes, methods, or fields.

like image 74
Louis Wasserman Avatar answered Nov 01 '22 18:11

Louis Wasserman


In your unit tests, setup an aspect to log and/or fail when any of the beta classes (or any unwelcome class) is used.

like image 42
DwB Avatar answered Nov 01 '22 18:11

DwB


Apparently Google Guava has an @Beta annotation which indicates which classes or methods you don't want to use.

Unfortunalty this annotation is @Retention(value=CLASS) which I've never used but since it's supposed to be kept in .class files it might mean that it will still be availiable to Class.getDeclaredAnnotations(). If it's not you will have to use CGLIB or similar bytecode level library to find it.

Given that you might want to instrument your CI application or add a checking classloader to your app to detect usage of beta API

like image 26
Cerber Avatar answered Nov 01 '22 18:11

Cerber