|
| 1 | +# TeaVM Java Support Limitations |
| 2 | + |
| 3 | +This document lists known Java APIs that don't work or have limited support in TeaVM's |
| 4 | +WebAssembly backend. Relevant when writing notebook examples or documentation. |
| 5 | + |
| 6 | +Reference: https://teavm.org/jcl-report/recent/jcl.html |
| 7 | + |
| 8 | +## Not Working |
| 9 | + |
| 10 | +### String Formatting |
| 11 | +- `String.format()` — throws error (missing Formatter/locale support) |
| 12 | +- `System.out.printf()` — same issue, uses Formatter internally |
| 13 | +- `Formatter` class — not implemented |
| 14 | +- **Workaround**: use string concatenation, `Math.round()` for decimal rounding |
| 15 | + |
| 16 | +### I/O & Input |
| 17 | +- `Scanner` — not available (no `System.in` in a browser) |
| 18 | +- `java.io.File`, `FileReader`, `FileWriter` — no filesystem access |
| 19 | +- `BufferedReader(new InputStreamReader(System.in))` — no stdin |
| 20 | +- **Workaround**: hardcode test values or use JS interop |
| 21 | + |
| 22 | +### Reflection |
| 23 | +- `Class.getDeclaredConstructor()`, `Class.getDeclaredMethod()` — throws SecurityException |
| 24 | +- `Method.invoke()` — not supported |
| 25 | +- `Class.forName()` — limited support |
| 26 | +- `java.lang.reflect` package — 9% fully implemented |
| 27 | +- **Workaround**: use TeaVM's metaprogramming API (compile-time only) |
| 28 | + |
| 29 | +### Networking |
| 30 | +- `java.net.URL`, `HttpURLConnection` — not supported |
| 31 | +- `java.net` package — 12% fully implemented |
| 32 | +- **Workaround**: use TeaVM's JS interop with `fetch()` |
| 33 | + |
| 34 | +### Serialization |
| 35 | +- `ObjectInputStream` / `ObjectOutputStream` — not supported |
| 36 | +- `Serializable` marker works but serialization mechanism doesn't |
| 37 | + |
| 38 | +### Class Loading |
| 39 | +- Custom `ClassLoader` — not supported |
| 40 | +- `Class.getResource()` / `getResourceAsStream()` — not available |
| 41 | + |
| 42 | +## Partially Working |
| 43 | + |
| 44 | +### Threading |
| 45 | +- `Thread` — emulated as green threads (coroutines), not real OS threads |
| 46 | +- `Thread.sleep()` — works (pauses the coroutine) |
| 47 | +- `synchronized` — compiles but is effectively single-threaded |
| 48 | +- `java.util.concurrent` — 13% fully implemented |
| 49 | +- `ConcurrentHashMap` — works (recent fix) |
| 50 | +- `AtomicReference`, `AtomicInteger`, `AtomicLong` — basic support |
| 51 | +- Most `Lock` classes — not available (`ReentrantLock` missing) |
| 52 | + |
| 53 | +### Streams |
| 54 | +- `java.util.stream` — 25% fully implemented |
| 55 | +- Basic `stream()`, `filter()`, `map()`, `collect()`, `reduce()` — work |
| 56 | +- Some collectors may be missing |
| 57 | +- `parallelStream()` — runs sequentially (no real threads) |
| 58 | + |
| 59 | +### Regex |
| 60 | +- `java.util.regex` — 50% fully implemented |
| 61 | +- `Pattern.compile()`, `Matcher` — basic patterns work |
| 62 | +- Some advanced regex features may be missing |
| 63 | +- Delegates to JavaScript's regex engine |
| 64 | + |
| 65 | +### Time |
| 66 | +- `java.time` — 63% fully implemented |
| 67 | +- `LocalDate`, `LocalTime`, `LocalDateTime`, `Instant` — work |
| 68 | +- `ZonedDateTime` — limited timezone detection |
| 69 | +- `DateTimeFormatter` — mostly works, some patterns may fail |
| 70 | + |
| 71 | +### Math |
| 72 | +- `java.math.BigDecimal` — works for basic operations |
| 73 | +- `java.math.BigInteger` — works for basic operations |
| 74 | + |
| 75 | +### Locale |
| 76 | +- Only `en_EN` locale included by default |
| 77 | +- Other locales need explicit configuration at compile time |
| 78 | + |
| 79 | +## Fully Working |
| 80 | + |
| 81 | +### Core |
| 82 | +- `java.lang.String` — all common methods (substring, charAt, indexOf, etc.) |
| 83 | +- `java.lang.Math` — fully supported |
| 84 | +- `java.lang.Integer`, `Long`, `Double`, etc. (boxing/unboxing) |
| 85 | +- `java.lang.StringBuilder` / `StringBuffer` |
| 86 | +- `java.lang.System.out.println()` — works |
| 87 | +- `java.lang.Exception` hierarchy — works |
| 88 | +- Generics, lambdas, method references — work |
| 89 | + |
| 90 | +### Collections |
| 91 | +- `java.util.ArrayList`, `LinkedList` |
| 92 | +- `java.util.HashMap`, `TreeMap`, `LinkedHashMap` |
| 93 | +- `java.util.HashSet`, `TreeSet` |
| 94 | +- `java.util.Collections` utility methods |
| 95 | +- `java.util.List.of()`, `Map.of()`, `Set.of()` (immutable factories) |
| 96 | +- `java.util.Optional` |
| 97 | +- `java.util.Iterator`, enhanced for-loop |
| 98 | +- `java.util.Arrays` — sort, fill, copyOf, etc. |
| 99 | + |
| 100 | +### Functional |
| 101 | +- `java.util.function` — 100% implemented |
| 102 | +- `Function`, `Consumer`, `Supplier`, `Predicate`, `BiFunction`, etc. |
| 103 | + |
| 104 | +### Other |
| 105 | +- `java.util.Objects` |
| 106 | +- `java.util.Random` (partial — basic nextInt/nextDouble work) |
| 107 | +- `java.util.zip` — jar/zip reading works (used by the compiler itself) |
| 108 | +- Records, sealed classes, pattern matching — compile correctly |
| 109 | +- `var` (local variable type inference) — works |
0 commit comments