Skip to content

fix: @INC duplication and PERL_USE_UNSAFE_INC support#513

Merged
fglock merged 1 commit intomasterfrom
fix/inc-duplication-and-unsafe-inc
Apr 20, 2026
Merged

fix: @INC duplication and PERL_USE_UNSAFE_INC support#513
fglock merged 1 commit intomasterfrom
fix/inc-duplication-and-unsafe-inc

Conversation

@fglock
Copy link
Copy Markdown
Owner

@fglock fglock commented Apr 20, 2026

Summary

Fixes two bugs that prevented Module::Install-based Makefile.PL scripts (e.g. Iterator::Simple) from running under jcpan.

Bug 1: @INC was duplicated at startup

$ ./jperl -e 'print join("|", @INC), "\n"'
/Users/fglock/.perlonjava/lib|jar:PERL5LIB|/Users/fglock/.perlonjava/lib|jar:PERL5LIB

GlobalContext.initializeGlobals() was being called re-entrantly. During Builtin.initialize() (invoked from inside initializeGlobals), an inheritFromrequiredoFile chain re-enters PerlLanguageProvider.executePerlCode, which checks globalInitialized. Because the flag was only set to true after initializeGlobals returned, the nested call ran the whole @INC population a second time.

Fix: set globalInitialized = true before calling initializeGlobals, at all three call sites.

Bug 2: PERL_USE_UNSAFE_INC was ignored

Module::Install's use inc::Module::Install; requires . in @INC. Modern Perl (5.26+) removed . from @INC by default, so CPAN.pm sets PERL_USE_UNSAFE_INC=1 when invoking Makefile.PL. jperl was ignoring this env var, making Module::Install-based distributions uninstallable.

Fix: GlobalContext.initializeGlobals() now appends . to @INC when PERL_USE_UNSAFE_INC is set to a truthy value.

Test plan

  • ./jperl -e 'print join("|", @INC), "\n"' shows no duplicates.
  • PERL_USE_UNSAFE_INC=1 ./jperl -e 'print join("|", @INC), "\n"' ends with ..
  • ./jcpan -t Iterator::Simple — all 67 tests across 11 files pass.
  • make — all unit tests pass.

Generated with Devin

Two bugs prevented Module::Install-based Makefile.PL scripts (e.g.
Iterator::Simple) from running under jcpan:

1. @inc was duplicated at startup. GlobalContext.initializeGlobals()
   was called re-entrantly: during Builtin.initialize() an
   inheritFrom -> require -> doFile chain re-entered
   PerlLanguageProvider.executePerlCode, which ran the whole @inc
   population a second time because globalInitialized was only set
   to true AFTER initializeGlobals returned. Fixed by setting the
   flag BEFORE the call at all three call sites.

2. PERL_USE_UNSAFE_INC was ignored. CPAN.pm sets this env var when
   invoking Makefile.PL so that `use inc::Module::Install;` can
   find ./inc/Module/Install.pm. jperl now appends "." to @inc
   when PERL_USE_UNSAFE_INC is set to a truthy value.

Verified with `./jcpan -t Iterator::Simple` (67 tests pass, 11
test files).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@fglock fglock merged commit 2cb689a into master Apr 20, 2026
2 checks passed
@fglock fglock deleted the fix/inc-duplication-and-unsafe-inc branch April 20, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant