Skip to content

Fix filehandle I/O error semantics and handle-based chdir #1187

Description

@fglock

CPAN compatibility failure

IO::Die 0.057 failed in CPAN run 20260828-172308-14550 (8 of 388 subtests).

The distribution is pure Perl. Focused upstream tests pass on system Perl 5.42, while both PerlOnJava backends reproduce the underlying failures.

Affected behavior

  1. chdir($directory_handle) fails with The fchdir function is unimplemented. System Perl accepts directory handles for chdir.
  2. Operations on invalid or closed filehandles do not follow Perl error semantics:
    • read(STDOUT, ...) succeeds even though STDOUT is not readable; IO::Die therefore cannot invoke a subclass's _CREATE_ERROR hook.
    • binmode($closed_handle) succeeds instead of failing with EBADF.
    • closedir($closed_handle) throws, but its error string has empty OS_ERROR and EXTENDED_OS_ERROR rather than Bad file descriptor.
    • chmod($filehandle) does not support the behavior exercised by IO::Die.

The original failures are in t/IO-Die.t: test_CREATE_ERROR, test_binmode, test_chdir, test_chmod, and test_closedir.

Reproducer

use IO::Die;

open my $fh, '<', '/dev/null' or die $!;
close $fh;
IO::Die->binmode($fh);

System Perl dies with a Binmode error containing :raw, layer, and Bad file descriptor. PerlOnJava returns success.

Likewise, this should succeed on a directory handle:

open my $dir, '<', '/' or die $!;
IO::Die->chdir($dir);

PerlOnJava reports fchdir as unimplemented.

Expected fix

Implement handle-based chdir, and make I/O operations consistently detect invalid descriptor state and preserve the correct OS error (EBADF) for wrapper code. Add focused project-owned regression coverage for JVM and interpreter backends.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions