728x90
[Rest][2023-08-02 18:39:02][ERROR][PostingController.java][lambda$doFindPostingActivity$5(92)] : readPosting
org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract boolean net.infobank.moyamo.repository.PostingRepository.isPostingOwner(long,java.lang.Long)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:229)
        at com.sun.proxy.$Proxy237.isPostingOwner(Unknown Source)
        at net.infobank.moyamo.service.PostingService.findPostingActivity(PostingService.java:1831)
        at net.infobank.moyamo.service.PostingService$$FastClassBySpringCGLIB$$72b2a0db.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
        at net.infobank.moyamo.service.PostingService$$EnhancerBySpringCGLIB$$886f7a7f.findPostingActivity(<generated>)
        at net.infobank.moyamo.controller.PostingController.lambda$doFindPostingActivity$4(PostingController.java:91)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:750)

 

Handling

The error message you are encountering (AopInvocationException: Null return value from advice does not match primitive return type) suggests that a method with a primitive return type (boolean in this case) is returning null. Since primitives cannot be null, this results in an exception.

Here's a brief rundown of what might be happening:

  1. Method Signature: The method isPostingOwner(long, java.lang.Long) in the PostingRepository interface is declared with a return type of boolean.
  2. Proxy Invocation: During the invocation, some AOP advice (such as a transactional aspect) may be being applied to this method.
  3. Null Return: For some reason, this method is returning null (possibly from a repository implementation or advice method), which is not compatible with the primitive boolean return type.

Here's how you can potentially resolve this:

1. Check the Repository Implementation

Ensure that the method's implementation in the corresponding repository class is not returning null. It should return a boolean value (true or false).

2. Check the AOP Advice

If there is any AOP (Aspect-Oriented Programming) advice being applied to the method, make sure that it's not altering the return value to null. Examine any aspects that might be affecting the method, including transactional aspects.

3. Change the Return Type (if applicable)

If it is acceptable for the method to indicate an absence of a value, consider changing the return type of the method from the primitive boolean to the wrapper class Boolean. This will allow the method to return null. Note that this will require handling the null value in the calling code.

Example:

javaCopy code
public abstract Boolean isPostingOwner(long id, java.lang.Long ownerId);

4. Exception Handling

If the null return is expected in some situations (like when some data is not found), consider adding proper exception handling in the method or its caller to deal with these scenarios gracefully.

By focusing on these areas, you should be able to track down the cause of the exception and resolve it. Make sure to thoroughly test your changes to ensure they don't introduce other issues.

 

 

 

JPOL 상에서 일치하지 않는 return type을 확인해서 boolean 에서 Boolean 으로 변경

@Query("select p.owner.id from Posting p where p.id = :postingId and p.owner.id = :userId")
Boolean isPostingOwner(@Param("postingId") long postingId, @Param("userId") Long userId);

 

추가적으로 null Pointer Exception handling

if(isWatch == null) {
    isWatch = !commentRepository.findDistinctRecipientByMentionUserIds(id, Collections.singletonList(user.getId())).isEmpty();
    Boolean isOwner = postingRepository.isPostingOwner(id, user.getId());
    isWatch = isWatch || (isOwner != null && isOwner);
}

 

을 했지만 문제발생으로 인한 JPQL 변경으로 처리

@Query("select case when count(p) > 0 then true else false end from Posting p where p.id = :postingId and p.owner.id = :userId")
Boolean isPostingOwner(@Param("postingId") long postingId, @Param("userId") Long userId);

+ Recent posts