Repository navigation
feat: add java.lang.System #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,21 +29,25 @@ | |
| "String", | ||
| "StringBuffer", | ||
| "StringBuilder", | ||
| "System", | ||
| "Thread", | ||
| "Throwable", | ||
| "UnsupportedOperationException", | ||
| ] | ||
|
|
||
| import __builtin__ as builtins | ||
| import array | ||
| import os | ||
| import time | ||
| from typing import TYPE_CHECKING, Any, List, Optional, Union | ||
|
|
||
| from java.lang.reflect import Type | ||
|
|
||
| if TYPE_CHECKING: | ||
| from java.io import InputStream, PrintStream | ||
| from java.nio import CharBuffer | ||
| from java.util import Iterator, Spliterator | ||
| from java.nio.channels import Channel | ||
| from java.util import Iterator, Properties, Spliterator | ||
| from java.util.function import Consumer | ||
| from java.util.stream import IntStream, Stream | ||
|
|
||
|
|
@@ -683,6 +687,153 @@ def trimToSize(self): | |
| pass | ||
|
|
||
|
|
||
| class System(Object): | ||
| """The System class contains several useful class fields and | ||
| methods. | ||
|
|
||
| It cannot be instantiated. Among the facilities provided by the | ||
| System class are standard input, standard output, and error output | ||
| streams; access to externally defined properties and environment | ||
| variables; a means of loading files and libraries; and a utility | ||
| method for quickly copying a portion of an array. | ||
| """ | ||
|
|
||
| err = None # type: PrintStream | ||
| in_ = None # type: InputStream | ||
| out = None # type: PrintStream | ||
|
Comment on lines
+701
to
+703
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Standard streams are unavailable When a caller accesses any standard stream, Initialize the fields to usable wrappers for the process’s standard error, input, and output streams. Prompt for AI agentsIn `src/java/lang/__init__.py` at lines 701-703:
**Standard streams are unavailable**
When a caller accesses any standard stream, `System.err`, `System.in_`, and `System.out` are initialized to `None`, so accessing a stream and calling its Java I/O methods fails with an attribute error instead of using the process’s standard streams.
Initialize the fields to usable wrappers for the process’s standard error, input, and output streams. |
||
|
|
||
| @staticmethod | ||
| def arraycopy(src, srcPos, dest, destPos, length): | ||
| # type: (Any, int, Any, int, int) -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def clearProperty(key): | ||
| # type: (Union[str, unicode]) -> Union[str, unicode] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Nullable returns are typed as non-null When a property is absent or has no previous value, or no inherited channel is available, the return annotations for Annotate these return values as optional strings or an optional channel, as appropriate. Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at line 712:
**Nullable returns are typed as non-null**
When a property is absent or has no previous value, or no inherited channel is available, the return annotations for `clearProperty`, `getProperty`, `setProperty`, and `inheritedChannel` exclude `None` even though these calls can return null, so type checkers allow callers to use missing values without handling them.
Annotate these return values as optional strings or an optional channel, as appropriate.
Also at `src/java/lang/__init__.py:755-756`, `src/java/lang/__init__.py:770`, `src/java/lang/__init__.py:828-829`, `stubs/stubs/java/lang/__init__.pyi:211`, `stubs/stubs/java/lang/__init__.pyi:229-231`, `stubs/stubs/java/lang/__init__.pyi:235`, `stubs/stubs/java/lang/__init__.pyi:257-260`. |
||
| pass | ||
|
|
||
| @staticmethod | ||
| def console(): | ||
| # type: () -> Any | ||
| pass | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Java accessors lack usable types When a caller uses these accessors and expects completion or type checking for their Java return values, Give the accessors their Java return types in the declarations and stubs, including distinct return types for the two Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at line 718:
**Java accessors lack usable types**
When a caller uses these accessors and expects completion or type checking for their Java return values, `console()`, `getenv()`, and `getLogger()` return `Any` in the declarations and stubs, so IDEs and type checkers cannot validate the `Console`, environment map or optional string, and `System.Logger` APIs.
Give the accessors their Java return types in the declarations and stubs, including distinct return types for the two `getenv()` forms.
Also at `stubs/stubs/java/lang/__init__.pyi:213`, `stubs/stubs/java/lang/__init__.pyi:221`, `stubs/stubs/java/lang/__init__.pyi:223`, `src/java/lang/__init__.py:737`, `src/java/lang/__init__.py:743`. |
||
|
|
||
| @staticmethod | ||
| def currentTimeMillis(): | ||
| # type: () -> long | ||
| return long(time.time() * 1000) | ||
|
|
||
| @staticmethod | ||
| def exit(status): | ||
| # type: (int) -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def gc(): | ||
| # type: () -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def getenv(name=None): | ||
| # type: (Optional[Union[str, unicode]]) -> Any | ||
| return dict(os.environ) if name is None else os.environ.get(str(name)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Null names expose the environment When a caller explicitly passes Distinguish an omitted argument from an explicitly passed Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at line 738:
**Null names expose the environment**
When a caller explicitly passes `None` as the environment-variable name, `getenv()` takes the no-argument branch and returns the entire environment instead of raising the null-argument error required by Java's named overload, exposing variables to the caller.
Distinguish an omitted argument from an explicitly passed `None` and raise the required null-argument error for the latter.
Also at `stubs/stubs/java/lang/__init__.pyi:221`.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Unicode names fail lookup When the caller supplies a non-ASCII Unicode environment-variable name, Convert Unicode names without ASCII encoding before looking them up in Prompt for AI agentsIn `src/java/lang/__init__.py` at line 738:
**Unicode names fail lookup**
When the caller supplies a non-ASCII Unicode environment-variable name, `getenv()` converts the name with `str(name)`, which attempts ASCII encoding under Python 2 and raises `UnicodeEncodeError` before the lookup, so callers cannot access the variable.
Convert Unicode names without ASCII encoding before looking them up in `os.environ`.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Environment snapshot can fail during updates When one thread calls Synchronize environment-map copying with updates, or handle copy failures and retry. Prompt for AI agentsIn `src/java/lang/__init__.py` at line 738:
**Environment snapshot can fail during updates**
When one thread calls `getenv()` without a name while another removes an entry from `os.environ`, `dict(os.environ)` copies the shared mapping without synchronization, so a concurrent thread that removes an environment entry can make the copy fail instead of returning a map.
Synchronize environment-map copying with updates, or handle copy failures and retry. |
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Environment changes succeed When a caller mutates the map returned by no-argument Return an unmodifiable mapping from the no-argument form of Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at line 739:
**Environment changes succeed**
When a caller mutates the map returned by no-argument `getenv()`, `getenv()` returns a mutable `dict`, so the mutation succeeds instead of raising the unsupported-operation error required by Java's unmodifiable environment map.
Return an unmodifiable mapping from the no-argument form of `getenv()`.
Also at `src/java/lang/__init__.py:736-738`. |
||
| @staticmethod | ||
| def getLogger(name, bundle=None): | ||
| # type: (Union[str, unicode], Optional[Any]) -> Any | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def getProperties(): | ||
| # type: () -> Properties | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def getProperty( | ||
| key, # type: Union[str, unicode] | ||
| def_=None, # type: Optional[Union[str, unicode]] | ||
| ): | ||
| # type: (...) -> Union[str, unicode] | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def getSecurityManager(): | ||
| # type: () -> Any | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def identityHashCode(x): | ||
| # type: (Object) -> int | ||
| return id(x) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Null identity hashes are wrong When the caller passes Accept an optional object and return Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at line 766:
**Null identity hashes are wrong**
When the caller passes `None`, `identityHashCode()` returns `id(None)` rather than Java's required `0`, and its `Object` annotation rejects null at type-check time, so callers get the wrong hash or cannot pass null.
Accept an optional object and return `0` when the argument is `None`.
Also at `stubs/stubs/java/lang/__init__.pyi:233`. |
||
|
|
||
| @staticmethod | ||
| def inheritedChannel(): | ||
| # type: () -> Channel | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def lineSeparator(): | ||
| # type: () -> Union[str, unicode] | ||
| return os.linesep | ||
|
|
||
| @staticmethod | ||
| def load(filename): | ||
| # type: (Union[str, unicode]) -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def loadLibrary(libname): | ||
| # type: (Union[str, unicode]) -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def mapLibraryName(libname): | ||
| # type: (Union[str, unicode]) -> Union[str, unicode] | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def nanoTime(): | ||
| # type: () -> long | ||
| return long(time.time() * 1000000000) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Elapsed-time readings jump When the system clock is adjusted while callers measure elapsed time, Implement Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at line 796:
**Elapsed-time readings jump**
When the system clock is adjusted while callers measure elapsed time, `System.nanoTime()` uses `time.time()`, so clock adjustments make successive readings jump or go backward and produce incorrect elapsed-time results.
Implement `nanoTime()` using a monotonic clock source.
Also at `src/java/lang/__init__.py:797`. |
||
|
|
||
| @staticmethod | ||
| def runFinalization(): | ||
| # type: () -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def setErr(err): | ||
| # type: (PrintStream) -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def setIn(in_): | ||
| # type: (InputStream) -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def setOut(out): | ||
| # type: (PrintStream) -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def setProperties(props): | ||
| # type: (Properties) -> None | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def setProperty( | ||
| key, # type: Union[str, unicode] | ||
| value, # type: Union[str, unicode] | ||
| ): | ||
| # type: (...) -> Union[str, unicode] | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def setSecurityManager(sm): | ||
| # type: (Any) -> None | ||
| pass | ||
|
|
||
|
|
||
| class Throwable(Object, builtins.Exception): | ||
| """The Throwable class is the superclass of all errors and | ||
| exceptions in the Java language. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ Low · System can be instantiated
When a caller invokes
System(),Systeminherits the instantiableObjectconstructor and defines no guard, so construction succeeds despite the class contract that it cannot be instantiated.Add a constructor guard that prevents callers from instantiating
System.Prompt for AI agents