diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py
index 8b3e012b7043570f5a0c362286ecac0b2469326b..190882c0b3a9b1e1882a164a309d75ed4b78d665 100644
--- a/python/dune/perftool/pdelab/localoperator.py
+++ b/python/dune/perftool/pdelab/localoperator.py
@@ -740,10 +740,11 @@ def generate_localoperator_kernels(operator):
         objective_jacobian = derivative(objective, objective.coefficients()[0])
 
         # Replace coefficient belonging to ansatz function with new coefficient
-        element = adjoint_jacform.coefficients()[0].ufl_element()
+        element = objective.coefficients()[0].ufl_element()
         coeff = Coefficient(element, count=3)
-        adjoint_jacform = replace(adjoint_jacform, {adjoint_jacform.coefficients()[0]: coeff})
         objective_jacobian = replace(objective_jacobian, {objective.coefficients()[0]: coeff})
+        if len(adjoint_jacform.coefficients()) > 0:
+            adjoint_jacform = replace(adjoint_jacform, {adjoint_jacform.coefficients()[0]: coeff})
 
         # Residual of the adjoint form
         adjoint_form = action(adjoint_jacform, original_form.coefficients()[0])