带有Java接口的Kotlin EJB抛出UndeclaredThrowableException
Java界面:
public interface IUserSettingManager { UserSettingApi updateSetting(Long userId, UserSetting userSettingNew) throws FailUpdateUserSettingException; }
Kotlin ejb:
@Stateless @Local(IUserSettingManager::class) open class UserSettingManager : DataManager(), IUserSettingManager { private companion object { private val LOG = LoggerFactory.getLogger(UserSettingManager::class.java) } @Throws(FailUpdateUserSettingException::class) private fun validate(userSetting: UserSetting) { if (userSetting.avatar?.length ?: 0 > DBConstant.UUID_VARCHAR_SIZE) { throw FailUpdateUserSettingException("avatar length") } } @Throws(FailUpdateUserSettingException::class) override fun updateSetting(userId: Long, userSettingNew: UserSetting): UserSettingApi { val logger = LOG.silentEnter("updateSetting") try { validate(userSettingNew) ..... } catch (ex: Exception) { val msg = "userId:$userId, user setting:$userSettingNew" when (ex) { is FailUpdateUserSettingException -> { logger.debug("$msg, ex:$ex") throw ex } else -> { logger.error(msg, ex) throw FailUpdateUserSettingException(ex.toString()) } } } } }
具有异常的Java类:
公共类FailUpdateUserSettingException扩展异常{
public FailUpdateUserSettingException() { this(error); }
}
当尝试使用不正确的数据调用ejb时,会得到异常UndeclaredThrowableException,并将结果事务处理转储
Caused by: java.lang.reflect.UndeclaredThrowableException at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:34) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59) [wildfly-ejb3-10.0.0.Final.jar:10.0.0.Final] at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:254) [wildfly-ejb3-10.0.0.Final.jar:10.0.0.Final] ... 137 more Caused by: com.pay.utils.shared.exception.user.FailUpdateUserSettingException: Fail update user setting. avatar length at com.pay.manager.UserSettingManager.validate(UserSettingManager.kt:xx) at com.pay.manager.UserSettingManager.updateSetting(UserSettingManager.kt:xx) at com.pay.manager.UserSettingManager.updateSetting(UserSettingManager.kt:xx) .....
结果
javax.ejb.EJBTransactionRolledbackException
我没有看到任何远程方法调用或任何序列化,这是这种类型的问题的常见原因,但它可能是类加载器的问题? 那个由Kotlin代码实例化的类是从一个不同的类加载器加载的,而不是由JBoss检查的那个类加载的,因此它被认为是一个无法识别的throwable?
我不知道如何检查。 EJB容器中的类加载器策略可能是 – 父 – 先与父 – 最后?
如果你用一个Java版本替换Kotlin代码,那么这种行为会是什么样的呢?这个Java版本总是会从私有的validate()方法中抛出这个异常,只是为了看看是否有所作为?
什么JDK版本,什么Kotlin版本,以及你使用的是什么JBoss版本?