apache/pulsar · error · RuntimeException

Unknown componentType

Error message

Unknown componentType 

What it means

ComponentTypeUtils.toString maps known ComponentType enum values (FUNCTION, SOURCE, SINK) to display strings and throws a RuntimeException for any other value. This acts as an exhaustive-switch guard: if a new ComponentType is added to the enum without updating this utility, runtime code that renders the type hits this error.

Source

Thrown at pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/ComponentTypeUtils.java:33

 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.pulsar.functions.utils;

import org.apache.pulsar.functions.proto.FunctionDetails;

public class ComponentTypeUtils {
    public static String toString(FunctionDetails.ComponentType componentType) {
        switch (componentType) {
            case FUNCTION:
                return "Function";
            case SOURCE:
                return "Source";
            case SINK:
                return "Sink";
            default:
                throw new RuntimeException("Unknown componentType " + componentType);
        }
    }
}

View on GitHub (pinned to 820761864e)

Solutions

  1. Upgrade the pulsar-functions-utils module so ComponentTypeUtils handles the new ComponentType constant
  2. Add a case for the new enum value to the switch in ComponentTypeUtils.toString
  3. Check for null before calling toString and map it to a valid ComponentType explicitly

Example fix

// before
case SINK: return "Sink";
default: throw new RuntimeException("Unknown componentType " + componentType);
// after
case SINK: return "Sink";
case NEW_TYPE: return "NewType";
default: throw new RuntimeException("Unknown componentType " + componentType);
Defensive patterns

Strategy: try-catch

Validate before calling

boolean knownType = componentType == ComponentType.FUNCTION
        || componentType == ComponentType.SOURCE
        || componentType == ComponentType.SINK;
if (!knownType) { /* handle/log before calling ComponentTypeUtils.toString */ }

Type guard

static boolean isKnownComponentType(ComponentType t) {
    return t == ComponentType.FUNCTION || t == ComponentType.SOURCE || t == ComponentType.SINK;
}

Try / catch

try {
    String name = ComponentTypeUtils.toString(componentType);
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Unknown componentType")) { /* upgrade module or map the new type */ }
}

Prevention

When it happens

Trigger: Calling ComponentTypeUtils.toString(componentType) with a ComponentType value not handled by the switch — practically, a newly added enum constant (e.g. a future component kind) or a null/default-uninitialized value passed as componentType.

Common situations: upgrading Pulsar where new ComponentType constants exist but older ConnectorUtils/toString code is on the classpath; custom code constructing ComponentType values directly; passing null into the utility.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/0216aa5cb4c70fa8. Report an issue: GitHub.