Workflow keeps retrying until max when the Exception is in FailWorkflowExceptionTypes

I am running a workflow in java sdk. I have registered exception type in FailWorkflowExceptionTypes of the worker. When there is exception, it doesn’t fail the workflow and retries it until the max attempts.
Simplified code that simulate the behavior is below,

public class HelloTest {
  static final String TASK_QUEUE = "mytaskqueue";
  static final String WORKFLOW_ID = "HelloExceptionWorkflow";

  @WorkflowInterface
  public interface MyWorkflow {
    @WorkflowMethod
    String workflowMethod(String greeting, String name);
  }

  @ActivityInterface
  public interface MyActivity {
    String activityMethod(String greeting, String name);
  }
  public static class MyWorkflowChildImpl implements MyWorkflow {
    private final MyActivity activities =
        Workflow.newActivityStub(
            MyActivity.class,
            ActivityOptions.newBuilder()
                .setStartToCloseTimeout(Duration.ofMinutes(1))
                .setScheduleToStartTimeout(Duration.ofSeconds(5))
                .setRetryOptions(
                    RetryOptions.newBuilder()
                        .setInitialInterval(Duration.ofSeconds(1))
                        .setMaximumAttempts(5)
                        .build())
                .build());

    @Override
    public String workflowMethod(String greeting, String name) {
      return activities.activityMethod(greeting, name);
    }
  }

  static class MyActivityImpl implements MyActivity {

    public String activityMethod(String greeting, String name) {
      throw new IllegalStateException("this is intentional");
    }
  }

  public static void main(String[] args) {

    // Define the workflow service.
    WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs();
    WorkflowClient client = WorkflowClient.newInstance(service);
    WorkerFactory factory = WorkerFactory.newInstance(client);
    Worker worker = factory.newWorker(TASK_QUEUE);
    WorkflowImplementationOptions options =
        WorkflowImplementationOptions.newBuilder()
            .setFailWorkflowExceptionTypes(IllegalStateException.class)
            .build();
    worker.registerWorkflowImplementationTypes(options, MyWorkflowChildImpl.class);
    worker.registerActivitiesImplementations(new MyActivityImpl());
    factory.start();

    WorkflowOptions workflowOptions =
        WorkflowOptions.newBuilder().setWorkflowId(WORKFLOW_ID).setTaskQueue(TASK_QUEUE).build();
    MyWorkflow myWorkflow = client.newWorkflowStub(MyWorkflow.class, workflowOptions);
    myWorkflow.workflowMethod("hello", "test");
  }
}

Is this a bug, or am I missing something here?

Activity exception is always wrapped in an ActivityFailure. So you either need to throw a different exception from the workflow or add ActivityFailure to the list of failed workflow types.

Thanks @maxim . Where does the failWorkflowExceptionType apply then?

It applies to exceptions thrown from a workflow. In your case an ActivityFailure is thrown.