Repository navigation
feat: add java.lang.System #56
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 |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| "String", | ||
| "StringBuffer", | ||
| "StringBuilder", | ||
| "System", | ||
| "Thread", | ||
| "Throwable", | ||
| "UnsupportedOperationException", | ||
|
|
@@ -40,15 +41,18 @@ | |
|
|
||
| import __builtin__ as builtins | ||
| import array | ||
| import os | ||
| import time | ||
| from typing import TYPE_CHECKING, Any, List, Optional, Set, Union | ||
|
|
||
| from java.lang.reflect import AccessFlag, Type | ||
|
|
||
| if TYPE_CHECKING: | ||
| from java.io import InputStream, PrintStream | ||
| from java.nio import CharBuffer | ||
| from java.nio.channels import Channel | ||
| from java.time import Duration | ||
| from java.util import Iterator, Spliterator | ||
| from java.util import Iterator, Properties, Spliterator | ||
| from java.util.concurrent import ThreadFactory | ||
| from java.util.function import Consumer, Supplier | ||
| from java.util.stream import IntStream, Stream | ||
|
|
@@ -714,6 +718,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
+732
to
+734
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 unusable When callers access or replace a standard stream, Initialize the standard stream fields to usable streams and make each setter update its corresponding field. Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at lines 732-734:
**Standard streams are unusable**
When callers access or replace a standard stream, `System.err`, `System.in_`, and `System.out` remain `None`, and `setErr`, `setIn`, and `setOut` do not update them, so callers cannot use or retain a usable standard stream.
Initialize the standard stream fields to usable streams and make each setter update its corresponding field.
Also at `src/java/lang/__init__.py:834`, `src/java/lang/__init__.py:839`, `src/java/lang/__init__.py:844`. |
||
|
|
||
| @staticmethod | ||
| def arraycopy(src, srcPos, dest, destPos, length): | ||
| # type: (Any, int, Any, int, int) -> None | ||
| dest[destPos : destPos + length] = src[srcPos : srcPos + length] | ||
|
Comment on lines
+737
to
+739
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 · Invalid copies corrupt arrays When a copy has a negative position or length, or either requested range extends beyond its array, Validate the positions and length against both arrays before copying, and reject invalid ranges without modifying the destination. Prompt for AI agentsIn `src/java/lang/__init__.py` at lines 737-739:
**Invalid copies corrupt arrays**
When a copy has a negative position or length, or either requested range extends beyond its array, `arraycopy` uses Python slice assignment, which clips invalid ranges and can resize the destination instead of rejecting the copy, so callers see silently corrupted arrays rather than a bounds error.
Validate the positions and length against both arrays before copying, and reject invalid ranges without modifying the destination. |
||
|
|
||
| @staticmethod | ||
| def clearProperty(key): | ||
| # type: (Union[str, unicode]) -> Union[str, unicode] | ||
|
Comment on lines
+742
to
+743
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 results lack annotations When a property has no value or previous value, or there is no inherited channel, the runtime annotations and stub signatures promise non-null strings or a channel even though these APIs can return Mark the affected property and inherited-channel return types as optional in both the runtime annotations and the stubs. Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at lines 742-743:
**Nullable results lack annotations**
When a property has no value or previous value, or there is no inherited channel, the runtime annotations and stub signatures promise non-null strings or a channel even though these APIs can return `None`, so type-checked callers are not warned before dereferencing a null result.
Mark the affected property and inherited-channel return types as optional in both the runtime annotations and the stubs.
Also at `src/java/lang/__init__.py:744`, `src/java/lang/__init__.py:782-783`, `src/java/lang/__init__.py:798`, `src/java/lang/__init__.py:852-853`, `stubs/stubs/java/lang/__init__.pyi:231-232`, `stubs/stubs/java/lang/__init__.pyi:247-249`, `stubs/stubs/java/lang/__init__.pyi:255`, `stubs/stubs/java/lang/__init__.pyi:277-279`. |
||
| 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. 🟠 High · Property APIs return no state When callers set, clear, or read a system property, Implement the property APIs against shared process property state and return the values required by each operation. Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at line 744:
**Property APIs return no state**
When callers set, clear, or read a system property, `clearProperty`, `getProperties`, `getProperty`, `setProperties`, and `setProperty` are no-ops, so property changes are not shared and callers receive `None` instead of usable results.
Implement the property APIs against shared process property state and return the values required by each operation.
Also at `src/java/lang/__init__.py:779`, `src/java/lang/__init__.py:784`, `src/java/lang/__init__.py:849-850`, `src/java/lang/__init__.py:854-855`. |
||
|
|
||
| @staticmethod | ||
| def console(): | ||
| # type: () -> Any | ||
| pass | ||
|
|
||
| @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)) | ||
|
Comment on lines
+767
to
+769
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 · Invalid names return results When a caller passes Distinguish the no-argument overload from an explicit Also at Prompt for AI agentsIn `src/java/lang/__init__.py` at lines 767-769:
**Invalid names return results**
When a caller passes `None` or an empty string as the name, `getenv()` treats explicit `None` like the no-argument overload and returns the environment map, while an empty name returns `None`, instead of rejecting these names as Java does.
Distinguish the no-argument overload from an explicit `None`, and raise the required exception for null or empty names.
Also at `stubs/stubs/java/lang/__init__.pyi:241`.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 map accepts mutation When a caller tries to modify the map returned by Return an unmodifiable view or mapping for the no-argument Prompt for AI agentsIn `src/java/lang/__init__.py` at line 769:
**Environment map accepts mutation**
When a caller tries to modify the map returned by `getenv()` with no name, `getenv()` returns a mutable dictionary, so modifications are accepted even though Java requires the environment map to be unmodifiable.
Return an unmodifiable view or mapping for the no-argument `getenv()` overload.
Comment on lines
+767
to
+769
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 environment names raise encoding errors When the caller supplies a non-ASCII Convert Unicode names using the platform's environment encoding before looking them up. Prompt for AI agentsIn `src/java/lang/__init__.py` at lines 767-769:
**Unicode environment names raise encoding errors**
When the caller supplies a non-ASCII `unicode` environment-variable name, on Python 2, `str()` encodes a non-ASCII `unicode` value using the default ASCII encoding, so `getenv()` raises `UnicodeEncodeError` instead of looking up a valid environment name.
Convert Unicode names using the platform's environment encoding before looking them up. |
||
|
|
||
| @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) | ||
|
Comment on lines
+795
to
+797
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 hash differs When the argument is Return zero when the argument is Prompt for AI agentsIn `src/java/lang/__init__.py` at lines 792-794:
**Null identity hash differs**
When the argument is `None`, `identityHashCode()` returns Python’s nonzero `id(None)`, but Java specifies zero for a null reference, so callers receive the wrong hash.
Return zero when the argument is `None`. |
||
|
|
||
| @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) | ||
|
Comment on lines
+825
to
+827
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 · Elapsed-time measurements jump When the system wall clock is adjusted while a caller measures an interval, Use a monotonic clock source for Prompt for AI agentsIn `src/java/lang/__init__.py` at lines 822-824:
**Elapsed-time measurements jump**
When the system wall clock is adjusted while a caller measures an interval, `nanoTime()` derives its value from adjustable `time.time()`, so clock corrections make readings jump or decrease and callers get invalid elapsed durations, including negative ones.
Use a monotonic clock source for `nanoTime()`. |
||
|
|
||
| @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 constructs
System(),Systeminherits the publicObject.__init__(), so construction succeeds even though this utility class cannot be instantiated in Java.Prevent instances of
Systemfrom being constructed.Also at
stubs/stubs/java/lang/__init__.pyi:222.Prompt for AI agents