apache/dubbo · error · UnsupportedOperationException

source == null

Error message

source == null

What it means

Thrown by JavaFileObjectImpl.getCharContent when source is null. This happens when a JavaFileObjectImpl was constructed for output (CLASS kind) or by URI, which do not carry source text, yet the compiler framework calls getCharContent expecting to read source.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/JdkCompiler.java:156

        public JavaFileObjectImpl(final String baseName, final CharSequence source) {
            super(ClassUtils.toURI(baseName + ClassUtils.JAVA_EXTENSION), Kind.SOURCE);
            this.source = source;
        }

        JavaFileObjectImpl(final String name, final Kind kind) {
            super(ClassUtils.toURI(name), kind);
            source = null;
        }

        public JavaFileObjectImpl(URI uri, Kind kind) {
            super(uri, kind);
            source = null;
        }

        @Override
        public CharSequence getCharContent(final boolean ignoreEncodingErrors) throws UnsupportedOperationException {
            if (source == null) {
                throw new UnsupportedOperationException("source == null");
            }
            return source;
        }

        @Override
        public InputStream openInputStream() {
            return new ByteArrayInputStream(getByteCode());
        }

        @Override
        public OutputStream openOutputStream() {
            return bytecode = new ByteArrayOutputStream();
        }

        public byte[] getByteCode() {
            return bytecode.toByteArray();
        }
    }

View on GitHub (pinned to 3a3043227f)

Solutions

  1. This is typically internal to JdkCompiler; ensure you are using a supported Compiler SPI and not calling JavaFileObjectImpl directly.
  2. Upgrade Dubbo to a version where the JdkCompiler file-object lifecycle is correctly managed.
  3. If extending JdkCompiler, only call getCharContent on file objects constructed with source text.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    fileObject.getCharContent(true);
} catch (UnsupportedOperationException e) {
    // this file object has no source; use one created with source text
}

Prevention

When it happens

Trigger: The JSR-199 framework or internal code calls getCharContent on a JavaFileObjectImpl that was created via the (name, Kind) or (URI, Kind) constructors (source == null) instead of the (baseName, CharSequence) constructor.

Common situations: An internal Dubbo JdkCompiler path where the file manager hands a class-output file object to a code path that then tries to read its source. Generally an internal/library-internal condition rather than a direct user API misuse.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/4d2633c72948ec31. Report an issue: GitHub.