# UNDF: UNDF-2026-000000506
# pulsar-0002: JavaInstanceRunnable — List.contains() inside config key validation loop

## Defect ID
pulsar-0002

## File:Line
`pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceRunnable.java:987`

## Description
In `setupConfig()`:

```java
final List<String> allFields = BeanPropertiesReader.getBeanProperties(configClass); // List<String>
for (String s : config.keySet()) {           // O(K) iterations over config keys
    if (!allFields.contains(s)) {            // O(F) linear scan over field names
        ...
    }
}
```

`allFields` is a `List<String>` returned by `BeanPropertiesReader.getBeanProperties()`.
Each `.contains()` is O(F) where F = number of bean fields. Total: O(K × F).

While this runs at function startup (not hot per-message), it runs once per function
instance initialization. For a config class with 200 fields and 150 config keys,
this is 30,000 comparisons vs 350 with a HashSet.

## Complexity
- Slow: O(K × F) — List.contains() = O(F)
- Fast: O(K) — HashSet.contains() = O(1)

## Severity
MEDIUM

## Speedup Estimate
~F× improvement = 200x at F=200 fields.

## Fix
Convert `allFields` to `HashSet<String>` immediately after retrieval:

```java
Set<String> allFieldsSet = new HashSet<>(BeanPropertiesReader.getBeanProperties(configClass));
for (String s : config.keySet()) {
    if (!allFieldsSet.contains(s)) { ... }
}
```
