Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/pip-compile-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
branch: ['8.1', '8.3']
branch: ['17', '25']
fail-fast: false
steps:
- name: Checkout repo
Expand All @@ -19,26 +19,26 @@ jobs:
ref: ${{ matrix.branch }}

- name: Upgrade package requirements
uses: coatl-dev/actions/pip-compile-upgrade@499c77f2bc6f909d372849058517ca2e39ce16d4 # v7.1.3
uses: coatl-dev/actions/pip-compile-upgrade@c339f0299e21b3b28b42414e3ea474d33468713c # v7.1.5
with:
path: requirements.txt

- name: Upgrade stubs requirements
uses: coatl-dev/actions/uv-pip-compile-upgrade@499c77f2bc6f909d372849058517ca2e39ce16d4 # v7.1.3
uses: coatl-dev/actions/uv-pip-compile-upgrade@c339f0299e21b3b28b42414e3ea474d33468713c # v7.1.5
with:
path: requirements.txt
python-version: '3.12'
working-directory: stubs

- name: Detect changes
id: git-diff
uses: coatl-dev/actions/simple-git-diff@499c77f2bc6f909d372849058517ca2e39ce16d4 # v7.1.3
uses: coatl-dev/actions/simple-git-diff@c339f0299e21b3b28b42414e3ea474d33468713c # v7.1.5
with:
path: ${{ github.workspace }}

- name: Import GPG key
if: ${{ steps.git-diff.outputs.diff == 'true' }}
uses: coatl-dev/actions/gpg-import@499c77f2bc6f909d372849058517ca2e39ce16d4 # v7.1.3
uses: coatl-dev/actions/gpg-import@c339f0299e21b3b28b42414e3ea474d33468713c # v7.1.5
with:
passphrase: ${{ secrets.COATL_BOT_GPG_PASSPHRASE }}
private-key: ${{ secrets.COATL_BOT_GPG_PRIVATE_KEY }}
Expand All @@ -63,7 +63,7 @@ jobs:
- name: Create pull request
if: ${{ steps.git-diff.outputs.diff == 'true' }}
uses: coatl-dev/actions/pr-create@499c77f2bc6f909d372849058517ca2e39ce16d4 # v7.1.3
uses: coatl-dev/actions/pr-create@c339f0299e21b3b28b42414e3ea474d33468713c # v7.1.5
with:
gh-token: ${{ secrets.COATL_BOT_GH_TOKEN }}
base-branch: '${{ matrix.branch }}'
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ keywords =
inductive automation
java
project_urls =
Documentation = https://docs.oracle.com/en/java/javase/17/docs/api/index.html
Documentation = https://docs.oracle.com/en/java/javase/25/docs/api/index.html
Funding = https://github.com/sponsors/cesarcoatl
Source = https://github.com/ignition-devs/java-api/tree/main
Source = https://github.com/ignition-devs/java-api/tree/25
Tracker = https://github.com/ignition-devs/java-api/issues

[options]
Expand Down
153 changes: 152 additions & 1 deletion src/java/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"String",
"StringBuffer",
"StringBuilder",
"System",
"Thread",
"Throwable",
"UnsupportedOperationException",
Expand All @@ -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
Expand Down Expand Up @@ -714,6 +718,153 @@ def trimToSize(self):
pass


class System(Object):

Copy link
Copy Markdown

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(), System inherits the public Object.__init__(), so construction succeeds even though this utility class cannot be instantiated in Java.

Prevent instances of System from being constructed.

Also at stubs/stubs/java/lang/__init__.pyi:222.

Prompt for AI agents
In `src/java/lang/__init__.py` at line 721:

**System can be instantiated**

When a caller constructs `System()`, `System` inherits the public `Object.__init__()`, so construction succeeds even though this utility class cannot be instantiated in Java.

Prevent instances of `System` from being constructed.

Also at `stubs/stubs/java/lang/__init__.pyi:222`.

"""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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 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.

Prompt for AI agents
In `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`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 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.

Prompt for AI agents
In `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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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, 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().

Prompt for AI agents
In `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.
Expand Down
2 changes: 1 addition & 1 deletion stubs/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ classifiers = [
urls.Documentation = "https://docs.oracle.com/en/java/javase/25/docs/api/index.html"
urls.Funding = "https://github.com/sponsors/cesarcoatl"
urls.Homepage = "https://github.com/ignition-devs/java-api"
urls.Source = "https://github.com/ignition-devs/java-api/tree/main"
urls.Source = "https://github.com/ignition-devs/java-api/tree/25"
urls.Tracker = "https://github.com/ignition-devs/java-api/issues"

[tool.setuptools]
Expand Down
65 changes: 64 additions & 1 deletion stubs/stubs/java/lang/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import __builtin__ as builtins
from typing import Any, List, Optional, Set, Union

from java.io import InputStream, PrintStream
from java.lang.reflect import AccessFlag, Type
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
Expand Down Expand Up @@ -217,6 +219,67 @@ class StringBuilder(Object, CharSequence):
def substring(self, start: int, end: int = ...) -> Union[str, unicode]: ...
def trimToSize(self) -> None: ...

class System(Object):
err: PrintStream
in_: InputStream
out: PrintStream
@staticmethod
def arraycopy(
src: Any, srcPos: int, dest: Any, destPos: int, length: int
) -> None: ...
@staticmethod
def clearProperty(key: Union[str, unicode]) -> Union[str, unicode]: ...
@staticmethod
def console() -> Any: ...
@staticmethod
def currentTimeMillis() -> long: ...
@staticmethod
def exit(status: int) -> None: ...
@staticmethod
def gc() -> None: ...
@staticmethod
def getenv(name: Optional[Union[str, unicode]] = ...) -> Any: ...
@staticmethod
def getLogger(name: Union[str, unicode], bundle: Optional[Any] = ...) -> Any: ...
@staticmethod
def getProperties() -> Properties: ...
@staticmethod
def getProperty(
key: Union[str, unicode], def_: Optional[Union[str, unicode]] = ...
) -> Union[str, unicode]: ...
@staticmethod
def getSecurityManager() -> Any: ...
@staticmethod
def identityHashCode(x: Object) -> int: ...
@staticmethod
def inheritedChannel() -> Channel: ...
@staticmethod
def lineSeparator() -> Union[str, unicode]: ...
@staticmethod
def load(filename: Union[str, unicode]) -> None: ...
@staticmethod
def loadLibrary(libname: Union[str, unicode]) -> None: ...
@staticmethod
def mapLibraryName(libname: Union[str, unicode]) -> Union[str, unicode]: ...
@staticmethod
def nanoTime() -> long: ...
@staticmethod
def runFinalization() -> None: ...
@staticmethod
def setErr(err: PrintStream) -> None: ...
@staticmethod
def setIn(in_: InputStream) -> None: ...
@staticmethod
def setOut(out: PrintStream) -> None: ...
@staticmethod
def setProperties(props: Properties) -> None: ...
@staticmethod
def setProperty(
key: Union[str, unicode], value: Union[str, unicode]
) -> Union[str, unicode]: ...
@staticmethod
def setSecurityManager(sm: Any) -> None: ...

class Throwable(Object, builtins.Exception):
def __init__(
self, message: Optional[str] = ..., cause: Optional[Throwable] = ...
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ wrap-summaries = 72
arg-type-hints-in-docstring = False
arg-type-hints-in-signature = False
check-return-types = False
ignore = DOC202, E741, F821
ignore = DOC202, E203, E741, F821
max-complexity = 10
max-doc-length = 72
max-line-length = 120
Expand Down
Loading