Menu

#1 Exempt DESTROY from AUTOLOAD

open
nobody
None
5
2007-10-02
2007-10-02
fyneman
No

In bsfperl.pl, method BSF::UNIVERSAL::import should not try to call a java method DESTROY on a perl object. If the perl class does not have a DESTROY method defined, bsfperl will try to call a java DESTROY method on the class and java will throw a "class not found" exception.

Recommend the following line of code be added

return if $method eq 'DESTROY';

as in

sub UNIVERSAL::import {
my ($class) = @_;

my $short = ($class =~ /([^:]+)$/)[0] || $class;

no strict 'refs';
my %h = %{$short . "::"};

unless (exists $h{"AUTOLOAD"}) {
*{$short . "::AUTOLOAD"} = sub {
my ($givenClass) = shift;
my $method = ($AUTOLOAD =~ /([^:]+)$/)[0] || $AUTOLOAD;

return if $method eq 'DESTROY';

my $javaClassName = $class;
$javaClassName =~ s/::/./g;

my $beanName = $javaClassName . ".class";
my $javaClass = BSF::JavaObject->new($beanName);
return $javaClass->_callMethod($method, @_);
};
}
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.