{"record":{"id":"683bb311a80a8e49","repo":"apache/pulsar","slug":"stream-is-not-supported","errorCode":null,"errorMessage":"stream is not supported","messagePattern":"stream is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentBitSet.java","lineNumber":430,"sourceCode":"        String str = super.toString();\n        if (!rwLock.validate(stamp)) {\n            // Fallback to read lock\n            stamp = rwLock.readLock();\n            try {\n                str = super.toString();\n            } finally {\n                rwLock.unlockRead(stamp);\n            }\n        }\n        return str;\n    }\n\n    /**\n     * This operation is not supported on {@code ConcurrentBitSet}.\n     */\n    @Override\n    public IntStream stream() {\n        throw new UnsupportedOperationException(\"stream is not supported\");\n    }\n\n    public boolean equals(final Object o) {\n        if (o == this) {\n            return true;\n        }\n        if (!(o instanceof ConcurrentBitSet)) {\n            return false;\n        }\n        long stamp = rwLock.tryOptimisticRead();\n        boolean isEqual = super.equals(o);\n        if (!rwLock.validate(stamp)) {\n            // Fallback to read lock\n            stamp = rwLock.readLock();\n            try {\n                isEqual = super.equals(o);\n            } finally {\n                rwLock.unlockRead(stamp);","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/collections/ConcurrentBitSet.java#L412-L448","documentation":"ConcurrentBitSet.stream() is explicitly unsupported: the class overrides IntStream stream() only to throw UnsupportedOperationException(\"stream is not supported\"), because materializing a stream from a lock-striped concurrent bit set cannot provide the snapshot semantics callers expect. The compiler will accept the call; the failure happens only at runtime.","triggerScenarios":"Calling stream() on a ConcurrentBitSet (not BitSetRecyclable) — e.g. generic code written against a BitSet-like abstraction, or refactoring code that used BitSetRecyclable/plain BitSet to use ConcurrentBitSet and kept the stream-based iteration.","commonSituations":"Switching a data structure to ConcurrentBitSet for thread safety without auditing all operations; library code that streams any BitSet; collecting acknowledged indices for logging/stats.","solutions":["Replace stream() with index-based iteration: loop i from 0 while calling nextSetBit(i) semantics if available, or use the word/index API","Use the underlying get()/nextClearBit-style iteration appropriate to ConcurrentBitSet's API","If a snapshot is needed, copy bits into a plain BitSet or int list under the caller's synchronization, then stream that","Audit generic code paths for UnsupportedOperationException when adopting ConcurrentBitSet"],"exampleFix":"// before\nIntStream indices = concurrentBitSet.stream();\n// after\nList<Integer> indices = new ArrayList<>();\nfor (int i = 0; i < concurrentBitSet.length(); i++) {\n    if (concurrentBitSet.get(i)) indices.add(i);\n}","handlingStrategy":"try-catch","validationCode":"// ConcurrentBitSet does not support stream(); iterate instead\nList<Integer> setBits = new ArrayList<>();\nfor (int i = 0; i < concurrentBitSet.length(); i++) {\n    if (concurrentBitSet.get(i)) setBits.add(i);\n}","typeGuard":"static boolean supportsStream(Object bitSet) { return !(bitSet instanceof ConcurrentBitSet); }","tryCatchPattern":"try {\n    stream = bitSet.stream();\n} catch (UnsupportedOperationException e) {\n    // fall back to index-based iteration\n    stream = indexBasedStream(bitSet);\n}","preventionTips":["Never call stream() on ConcurrentBitSet; its Javadoc marks it unsupported","When swapping in ConcurrentBitSet, audit all BitSet operations used","Prefer index-based iteration (get/nextSetBit-style) for concurrent sets","Keep a shared utility that iterates any BitSet-like type safely"],"tags":["java","bitset","unsupported-operation","concurrency"],"backgroundTag":"unsupported-operation","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}