Title: Sealed Classes in Java 17 — Spring AOP CGLIB Proxy Failure
Open Graph Title: Sealed Classes in Java 17 — Spring AOP CGLIB Proxy Failure
Description: Spring AOP's CGLIB proxy crashes sealed classes at startup with a JVM VerifyError. Fix: always inject via sealed interface, not concrete subtype.
Open Graph Description: Spring AOP's CGLIB proxy crashes sealed classes at startup with a JVM VerifyError. Fix: always inject via sealed interface, not concrete subtype.
Opengraph URL: https://thecodeforge.io/java/sealed-classes-java17/
Domain: thecodeforge.io
{
"@context": "https://schema.org",
"@type": "TechArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://thecodeforge.io/java/sealed-classes-java17/"
},
"headline": "Sealed Classes in Java 17 — Spring AOP CGLIB Proxy Failure",
"description": "Spring AOP's CGLIB proxy crashes sealed classes at startup with a JVM VerifyError. Fix: always inject via sealed interface, not concrete subtype.",
"keywords": "Sealed Classes in Java 17 — Spring AOP CGLIB Proxy Failure, Java, Advanced, Java 8+ Features, Spring AOP's CGLIB proxy crashes sealed classes at startup with a JVM VerifyError. Fix: always inject via sealed interface, not concrete subtype.",
"proficiencyLevel": "Expert",
"author": {
"@type": "Person",
"@id": "https://thecodeforge.io/about/#naren",
"name": "Naren",
"url": "https://thecodeforge.io/about/"
},
"publisher": {
"@type": "Organization",
"@id": "https://thecodeforge.io/#org",
"name": "TheCodeForge",
"url": "https://thecodeforge.io",
"logo": {"@type": "ImageObject", "url": "https://thecodeforge.io/assets/og-image.png"}
},
"datePublished": "2026-03-06T00:00:00+00:00",
"dateModified": "2026-08-30T00:00:00+00:00",
"url": "https://thecodeforge.io/java/sealed-classes-java17/",
"inLanguage": "en",
"educationalLevel": "Advanced",
"image": "https://thecodeforge.io/assets/og-image.png",
"isPartOf": {"@id": "https://thecodeforge.io/#website"}
}
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Home", "item": "https://thecodeforge.io/"},
{"@type": "ListItem", "position": 2, "name": "Java", "item": "https://thecodeforge.io/java/"},
{"@type": "ListItem", "position": 3, "name": "Sealed Classes in Java 17 — Spring AOP CGLIB Proxy Failure", "item": "https://thecodeforge.io/java/sealed-classes-java17/"}
]
}
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "Can I seal a class that already has subclasses outside the permits list?",
"acceptedAnswer": {
"@type": "Answer",
"text": "No—the compiler enforces that all existing direct subtypes must be in the `permits` list. Any subclass not listed will cause a compile error. You must either add it to `permits`, mark it `non-sealed`, or remove it."
}
},
{
"@type": "Question",
"name": "What happens if I use `non-sealed` on a subtype?",
"acceptedAnswer": {
"@type": "Answer",
"text": "The hierarchy is reopened for that branch. The compiler can no longer guarantee exhaustiveness over the sealed parent, so you'll need a `default` arm in switches. Use `non-sealed` sparingly."
}
},
{
"@type": "Question",
"name": "Can a sealed class be abstract?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes. Write `sealed abstract class`. It can have abstract methods and constructors. The sealed constraint applies regardless."
}
},
{
"@type": "Question",
"name": "Do sealed classes work with Java modules?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes, with extra rules: the sealed type must be exported from its module (`exports`), and permitted subtypes must be in the same module (or same package if no module). Cross-module subtypes require correct `requires` directives."
}
},
{
"@type": "Question",
"name": "Is there a performance penalty for using sealed classes?",
"acceptedAnswer": {
"@type": "Answer",
"text": "No—the opposite. The JIT can devirtualize method dispatch on sealed hierarchies with final subtypes, leading to 10-15% throughput gains on hot paths. The compiler overhead is negligible."
}
}
]
}
| og:type | website |
| og:image | https://thecodeforge.io/assets/og-image.png |
| og:image:width | 1200 |
| og:image:height | 630 |
Links:
Viewport: width=device-width, initial-scale=1.0
Robots: max-image-preview:large