Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6953055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:25:46+00:00 2026-05-27T14:25:46+00:00

Given the following code public interface Foo<T> { T get(); } @Remote public interface

  • 0

Given the following code

public interface Foo<T> {
    T get();
}

@Remote
public interface Bar extends Foo<String> {
}

@Stateless
public class BarImpl implements Bar {
    @Interceptors(ExceptionInterceptor.class)
    public String get() {
        throw new RuntimeException("not implemented");
    }
}

public class ExceptionInterceptor {
    @AroundInvoke
    public Object convertExceptionForExternalSystem(InvocationContext ctx) throws RuntimeException, Error {
        try
        {
            return ctx.proceed();
        }
        catch (Throwable e)
        {
            if (e instanceof Error)
                throw new Error("Changed");
            throw new RuntimeException("Changed");
        }
    }
}

When we call a method on the remote,

Bar bar = context.lookup(Bar.class.getName());
bar.get();

or

Foo foo = context.lookup(Bar.class.getName());
foo.get();

the interceptor is not called (using Glassfish 3.0.1).

The problem seems to be due to the fact that the compiled class file for the interface is

javap Foo
Compiled from "Foo.java"
public interface Foo{
    public abstract java.lang.Object get();
}

while for BarImpl it is

javap BarImpl
Compiled from "BarImpl.java"
public class BarImpl extends java.lang.Object implements Bar{
    public BarImpl();
    public java.lang.String get();
    public java.lang.Object get();
}

So, when we call

Bar bar = ...;
bar.get();

Internally the method

public java.lang.Object get(); 

is called, which will delegate to

public java.lang.String get();

Interceptors seem to only be invoked, when the latter is called directly. When I change the interface Bar to

@Remote
public interface Bar extends Foo<String> {
    @Override
    String get();
}

The interceptor is called in the first call (bar.get()), but not in the second call (foo.get()). Defining the interceptors on the class level might fix the proplem, but is not an option in our case.

Do we do something wrong, or is this a general problem of java-ee-6, or is this a bug in glassfish? Is there a workaround? Or should we abandon using generics in our Services at all?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:25:47+00:00Added an answer on May 27, 2026 at 2:25 pm

    Since we’re dealing with Java, type erasure takes over during runtime and your business interface will ever only contain:

    public Object get();
    

    You are casting the interface to Bar and that’s ok (no runtime class cast exception) but the business method that’s being called is the one present in the business interface (as that’s the only method the client knows about): the Object get() version.

    Also, since, by design, only business method invocations are intercepted, Object get() delegating on String get() does not get intercepted (it’s just a method calling another method). This means that, in your initial scenario, you’re trying to intercept a method that does not belong to the business interface and thus will never be intercepted.

    Since the EJB3 spec is really not clear about generics (mostly nothing is said), implementations really delegate that part on the JVM. There’s no way of getting true generic support in this scenario and I would say you’re stuck with class interceptors or changing your business interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following code: public interface IExample { ... } public abstract class BaseExample:
Given the following code: public interface Selectable { public void select(); } public class
Given the following code : public abstract class Participant { private String fullName; public
In c#, Given the following code: public class Person { public int PersonID {
Problem One friend suggested an interesting problem. Given the following code: public class OuterClass
Given the following example classes in my.package ... public class Foo { public void
Given the following code: using (var client = new WebClient()) { string url =
Given the following code, is there a way I can call class A's version
Given the following code, how do I resolve the right SomeInstance in autofac? public
Given the following code: using System.Collections.Generic; static class Program { static void Main() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.