8

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?

mjlee
  • 3,374
  • 4
  • 27
  • 22
  • Do keep in mind that there can be `@Beta` methods in classes that are not otherwise `@Beta`. Also, using `@Beta` APIs should not be a problem unless you're using them in a library that you're releasing. Using them in an _application_ should be fine... see [my answer here](http://stackoverflow.com/questions/3678122/best-way-to-use-guava/3678559#3678559). – ColinD Dec 27 '10 at 16:43
  • ColinD - Clarification - we are in a global team creating automated stock trading systems for various regions US, Europe, Asia, etc. ) We broke the system into various 'component/module' using maven. So each region can 'scaffold' these libraries to create different flavor of stock trading engines. So it is concern for me when we have development teams in 6 different regions and want to control how/what get used. I really want to use guava but avoid @Beta – mjlee Dec 27 '10 at 19:20

6 Answers6

5

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

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
2

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

DwB
  • 37,124
  • 11
  • 56
  • 82
1

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

Cerber
  • 2,889
  • 4
  • 27
  • 43
1

If you're using eclipse, access rules are one option. You'd get a compile-time error whenever you are importing or otherwise using a restricted class.

meriton
  • 68,356
  • 14
  • 108
  • 175
  • Can you please elaborate on how to configure Eclipse to automatically check for classes/methods marked as @Beta without manually putting all classes into the access rules list? – Peter Štibraný Jan 19 '12 at 09:20
  • Access rules only look at types by name, not by annotation, and not at individual methods. (That Beta was an annotation only became clear after I wrote this answer.) That said, I am pretty sure one could discover where eclipse stores that list, and write it automatically. – meriton Jan 19 '12 at 20:50
  • Ok, thanks. I was hoping that you found some secret trick I didn't know about :) – Peter Štibraný Jan 19 '12 at 21:42
0

I was thinking you could probably use reflection for that if you had a list of beta classes, which you can using Gili's link. Then it gets pretty easy - just see this answer:

Can you find all classes in a package using reflection?

I'd probably just put that in a unit test and have the unit test fail if it sees a class you don't like.

Community
  • 1
  • 1
Evan Reynolds
  • 450
  • 3
  • 11
0

Here is a list of Guava's Beta Classes.You will have to tell other developers to check this link before using a guava class.

Gili
  • 86,244
  • 97
  • 390
  • 689
Emil
  • 13,577
  • 18
  • 69
  • 108