The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →CGLib: The Missing Manual is Rafael Winterhalter’s practical 2013 guide to cglib, a Java library for generating classes and intercepting behavior at runtime. Its central lesson is that cglib can proxy concrete classes by generating subclasses, but that power comes with constraints: final classes and methods cannot be overridden, generated classes have class-loader lifecycle costs, and the library’s project health deserves consideration before you choose it for new work.
What is CGLib: The Missing Manual?
Winterhalter’s article fills a documentation gap with an overview of cglib’s runtime class generation and callback APIs. It is best read as an API tour rather than a complete language reference: it introduces the library’s major tools and shows the kinds of tasks they address, but it does not replace current project documentation or a compatibility check for a particular Java environment. Read the manual.
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
Book Eaters | $15.06 | Buy on Amazon |
| 2 |
|
How to Play from a Real Book: For All Musicians By Robert Rawlins | Real Book Guide for All... | $21.57 | Buy on Amazon |
| 3 |
|
The Penguin Book of Vampire Stories | $20.00 | Buy on Amazon |
| 4 |
|
The Spookiest Book Ever (Sammy Bird) | $2.99 | Buy on Amazon |
| 5 |
|
The Eerie Book | $21.49 | Buy on Amazon |
The article also captures a broader challenge in bytecode-generation libraries: useful capabilities can be difficult to adopt when developers cannot easily understand how generated code works. Winterhalter later made that point while discussing cglib and Byte Buddy. Meet Rafael Winterhalter and Byte Buddy.
How does cglib proxy a concrete class?
The standard JDK dynamic-proxy model wraps interfaces: a proxy implements one or more interfaces and dispatches calls to an invocation handler. cglib takes a different route. Its core entry point, Enhancer, generates a subclass of a target class (or an implementation for an interface) and routes eligible method calls through callback objects. That subclass-based design is what lets cglib proxy a concrete class rather than requiring the target type to be an interface.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →#1 Best Overall
Enhancer and callbacks
Configure an Enhancer with the superclass or interface and the callback policy, then create an instance of the generated type. A FixedValue callback can supply a replacement return value. A MethodInterceptor provides more control: it can inspect a call, decide how to respond, and, when appropriate, proceed to the original implementation. The manual’s examples illustrate these APIs; consult the article for its code-level tour. Enhancer and callback examples.
What cglib cannot override
Subclass proxies depend on overriding methods. A final class cannot be subclassed, and a final method cannot be overridden, so neither can be intercepted through this cglib approach. This is a structural limit, not a setting that can be switched off. If interception of such behavior is essential, choose a different design or instrumentation approach rather than expecting a cglib callback to bypass Java’s final modifier. Winterhalter’s discussion of cglib and Byte Buddy.
Rank #2
What else does the manual cover?
The article ranges well beyond proxies. These utilities are useful for different kinds of generated behavior and should not be treated as interchangeable:
| API | Purpose described in the manual |
|---|---|
ImmutableBean |
Wraps a bean to block writes through that wrapper. |
BeanCopier |
Generates property-copying code between beans. |
BulkBean |
Provides array-oriented access to bean properties. |
BeanMap |
Provides map-style access to bean properties. |
Mixin |
Combines interface-backed objects. |
InterfaceMaker |
Generates interfaces. |
MethodDelegate |
Generates a narrowly shaped forwarding interface for a method. |
MulticastDelegate |
Generates delegation that can forward calls to multiple targets. |
ConstructorDelegate |
Generates a factory-style interface around construction. |
ParallelSorter |
Sorts parallel arrays together. |
FastClass and FastMethod |
Generate invocation wrappers for methods. |
Proxy |
Offers cglib’s own proxy mechanism. |
The manual’s discussion of FastClass is qualitative, not a reproducible benchmark. It notes that modern HotSpot reflection inflation can reduce the need for generated invocation wrappers; it does not establish a general speed advantage with a measured figure. Full API overview.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
What operational risks should you consider?
Generated class lifecycle
Generated classes are not free of lifecycle consequences. They can be unloaded only when their defining class loader and the classes loaded through it become collectible. If an application continually generates classes or retains their loaders, the generated metadata may remain reachable and contribute to class-metadata memory pressure. Plan class generation and loader ownership deliberately, especially in long-running applications or systems that create many generated types. The manual’s closing guidance.
Compatibility and maintenance
Winterhalter’s later discussion points to Java 9 and newer module boundaries as a relevant concern for runtime code generation, particularly when generated classes interact with library-specific types. The available sources do not establish a current cglib release cadence or a definitive compatibility matrix, so check the project’s current status and test the exact Java versions and module configuration you deploy. Do not assume a library’s historical ability to generate subclasses guarantees compatibility in every modern module environment. Java modules and Byte Buddy discussion.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Should you use cglib or a different tool?
Choose according to the work you need to do, rather than treating every bytecode tool as a direct substitute. JDK proxies are a natural fit when your contract is already interface-based. cglib is useful when you specifically need subclass-based interception of a non-final class. Byte Buddy is presented by Winterhalter as a more capable option for modern Java module environments; Javassist and ASM are alternatives he recommends considering in light of cglib’s documentation and project concerns. These sources do not provide a current feature-by-feature matrix or benchmark, so evaluate candidates against the target Java runtime, required bytecode changes, and operational model.
| Approach | Useful when | Important qualification |
|---|---|---|
| JDK dynamic proxy | The proxy can implement the interfaces callers use. | Its standard proxy shape is interface-based; it does not create a subclass proxy for an arbitrary concrete class. |
cglib Enhancer |
You need subclass-based interception of eligible methods on a concrete class. | Final classes and methods cannot be intercepted by overriding; generated-class and class-loader lifecycle must be managed. |
| Byte Buddy | You need a more capable runtime-generation option, including work in modern module environments. | That positioning comes from Winterhalter’s discussion; verify current compatibility and features for your use case. |
| Javassist or ASM | You are considering alternatives at a different bytecode-generation level. | Winterhalter recommends considering them; the cited sources do not give a comparative benchmark or current support matrix. |
For new systems, project health is part of the technical decision. Winterhalter criticized cglib’s documentation, API organization, deployment history, and release cycles, and advised using it sparingly. His point is not that cglib is incapable, but that its power should be weighed against the cost of understanding and maintaining runtime-generated code. Manual’s concluding recommendation and later Byte Buddy discussion.
Quick Recap
Best Value
When is this manual useful?
- You have encountered cglib in an existing Java application and need a map of its APIs.
- You need to understand why a framework can intercept calls on a concrete class, or why a final class or method resists that interception.
- You are comparing proxying with bean utilities, delegation, or generated invocation helpers.
- You are assessing whether cglib’s lifecycle and maintenance trade-offs fit a new design, rather than assuming a proxy library is operationally invisible.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

