Bird
Raised Fist0
Spring Bootframework~20 mins

@Around advice for full control in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Master of @Around Advice
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this @Around advice code?
Consider this Spring Boot @Around advice that logs method execution time. What will be printed when the advised method completes successfully?
Spring Boot
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimingAspect {
    @Around("execution(* com.example.service.*.*(..))")
    public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();
        long duration = System.currentTimeMillis() - start;
        System.out.println("Execution time: " + duration + " ms");
        return proceed;
    }
}
AThrows a runtime exception because proceed() is not called.
BPrints nothing and returns null regardless of the method result.
CPrints 'Execution time: X ms' where X is the method duration, then returns the method result.
DPrints 'Execution time: 0 ms' always and returns the method result.
Attempts:
2 left
💡 Hint
Remember that joinPoint.proceed() runs the original method and returns its result.
📝 Syntax
intermediate
2:00remaining
Which option correctly uses @Around advice to modify the returned value?
You want to intercept a method and multiply its integer return value by 10 before returning it. Which @Around advice code snippet is correct?
A
@Around("execution(int com.example.*.*(..))")
public Object multiplyReturn(ProceedingJoinPoint pjp) throws Throwable {
    Object result = pjp.proceed();
    return (int) result * 10;
}
B
@Around("execution(int com.example.*.*(..))")
public Object multiplyReturn(ProceedingJoinPoint pjp) throws Throwable {
    int result = (int) pjp.proceed();
    return result * 10;
}
C
@Around("execution(int com.example.*.*(..))")
public int multiplyReturn(ProceedingJoinPoint pjp) {
    int result = (int) pjp.proceed();
    return result * 10;
}
D
@Around("execution(int com.example.*.*(..))")
public Object multiplyReturn(ProceedingJoinPoint pjp) throws Throwable {
    int result = pjp.proceed();
    return result * 10;
}
Attempts:
2 left
💡 Hint
Check method signature and casting carefully.
🔧 Debug
advanced
2:00remaining
Why does this @Around advice cause a StackOverflowError?
This advice is intended to log method calls but causes a StackOverflowError at runtime. What is the cause?
Spring Boot
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggingAspect {
    @Around("execution(* com.example.service.*.*(..))")
    public Object log(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("Before method");
        Object result = log(pjp); // recursive call instead of proceed()
        System.out.println("After method");
        return result;
    }
}
AThe advice returns null instead of the method result, causing a NullPointerException.
BThe pointcut expression is invalid, so the advice never runs and causes an error.
CThe advice does not declare 'throws Throwable', causing a compile error.
DThe advice calls itself recursively instead of calling pjp.proceed(), causing infinite recursion.
Attempts:
2 left
💡 Hint
Look at the method call inside the advice method.
❓ state_output
advanced
2:00remaining
What is the value of 'count' after this @Around advice runs three times?
This advice counts how many times methods in the service package are called. What is the value of 'count' after three method calls?
Spring Boot
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class CounterAspect {
    private int count = 0;

    @Around("execution(* com.example.service.*.*(..))")
    public Object countCalls(ProceedingJoinPoint pjp) throws Throwable {
        count++;
        return pjp.proceed();
    }

    public int getCount() {
        return count;
    }
}
A3
B0
C1
DThrows an error because 'count' is not thread-safe.
Attempts:
2 left
💡 Hint
Each method call increments count by one.
🧠 Conceptual
expert
2:00remaining
Which statement about @Around advice full control is TRUE?
Select the true statement about the capabilities of @Around advice in Spring AOP.
A@Around advice can modify method arguments, control method execution, and change the return value.
B@Around advice can only log method execution time but cannot alter method behavior or return values.
C@Around advice automatically retries the method on exceptions without extra code.
D@Around advice cannot access the original method's arguments or return value.
Attempts:
2 left
💡 Hint
Think about what full control means in this context.

Practice

(1/5)
1. What is the main purpose of using @Around advice in Spring AOP?
easy
A. To run code before and after a method, controlling its execution fully
B. To only run code after a method finishes
C. To replace the method with a new implementation without calling the original
D. To log method parameters without affecting execution

Solution

  1. Step 1: Understand the role of @Around advice

    @Around advice wraps a method, allowing code to run before and after the method execution.
  2. Step 2: Compare options with this behavior

    Only To run code before and after a method, controlling its execution fully describes full control before and after the method, matching @Around's purpose.
  3. Final Answer:

    To run code before and after a method, controlling its execution fully -> Option A
  4. Quick Check:

    @Around advice = full control before and after method [OK]
Hint: Remember @Around wraps method execution fully [OK]
Common Mistakes:
  • Thinking @Around only runs after method
  • Confusing @Around with @After or @Before
  • Forgetting @Around can modify inputs and outputs
2. Which of the following is the correct way to proceed with the original method inside an @Around advice method?
easy
A. return joinPoint.proceed();
B. joinPoint.execute();
C. proceed(joinPoint);
D. joinPoint.run();

Solution

  1. Step 1: Recall the method to call original execution

    In @Around advice, the original method is executed by calling joinPoint.proceed().
  2. Step 2: Match the correct syntax

    Only return joinPoint.proceed(); uses the correct method name and syntax to proceed.
  3. Final Answer:

    return joinPoint.proceed(); -> Option A
  4. Quick Check:

    Call original method with joinPoint.proceed() [OK]
Hint: Use joinPoint.proceed() to run original method [OK]
Common Mistakes:
  • Using incorrect method names like execute() or run()
  • Forgetting to return the result of proceed()
  • Calling proceed() without parentheses
3. Given the following @Around advice code, what will be printed when someMethod() returns "Hello"?
@Around("execution(* someMethod())")
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("Before");
    Object result = joinPoint.proceed();
    System.out.println("After");
    return result + " World";
}
medium
A. Before Hello After World
B. Hello Before After World
C. Before After Hello
D. Before After Hello World

Solution

  1. Step 1: Trace the advice execution order

    The advice prints "Before", then calls the original method which returns "Hello", then prints "After".
  2. Step 2: Understand the returned value

    The advice returns the original result plus " World", so the final returned string is "Hello World".
  3. Final Answer:

    Before After Hello World -> Option D
  4. Quick Check:

    Prints before and after, returns modified result [OK]
Hint: Remember @Around runs code before and after proceed() [OK]
Common Mistakes:
  • Assuming original method output is unchanged
  • Mixing print order with return value
  • Forgetting to add " World" to result
4. Identify the error in this @Around advice method:
@Around("execution(* someMethod())")
public Object aroundAdvice(ProceedingJoinPoint joinPoint) {
    System.out.println("Start");
    Object result = joinPoint.proceed();
    System.out.println("End");
    return result;
}
medium
A. Incorrect annotation syntax
B. Missing throws Throwable declaration in method signature
C. Should call joinPoint.execute() instead of proceed()
D. Cannot return Object type from advice

Solution

  1. Step 1: Check method signature requirements

    joinPoint.proceed() throws Throwable, so the advice method must declare throws Throwable or handle it.
  2. Step 2: Identify missing throws declaration

    The method lacks "throws Throwable", causing a compile error.
  3. Final Answer:

    Missing throws Throwable declaration in method signature -> Option B
  4. Quick Check:

    proceed() throws Throwable, must declare it [OK]
Hint: Add throws Throwable when calling joinPoint.proceed() [OK]
Common Mistakes:
  • Ignoring checked exceptions from proceed()
  • Using wrong method name instead of proceed()
  • Not matching annotation syntax
5. You want to create an @Around advice that modifies the input argument of a method before execution and changes the returned result after execution. Which approach correctly achieves this?
hard
A. Modify the method parameters directly without using proceed, then return null
B. Call joinPoint.proceed() without arguments, then ignore the result and return a new value
C. Modify the argument array via joinPoint.getArgs(), then call joinPoint.proceed(modifiedArgs), and finally modify the returned result before returning
D. Use joinPoint.proceed() and modify the result, but cannot change input arguments

Solution

  1. Step 1: Understand argument modification in @Around advice

    You can get and modify method arguments using joinPoint.getArgs() and pass them to proceed() to change inputs.
  2. Step 2: Modify the returned result after proceed()

    After calling proceed with modified arguments, you can change the returned value before returning it.
  3. Final Answer:

    Modify the argument array via joinPoint.getArgs(), then call joinPoint.proceed(modifiedArgs), and finally modify the returned result before returning -> Option C
  4. Quick Check:

    Change inputs with proceed(args), then modify output [OK]
Hint: Use proceed(modifiedArgs) to change inputs, then modify output [OK]
Common Mistakes:
  • Calling proceed() without modified arguments when inputs need change
  • Trying to change parameters directly without proceed()
  • Ignoring returned result modification
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard