Skip to content

Better warnings for deprecated java_import forms#7143

Merged
headius merged 1 commit intojruby:jruby-9.3from
headius:java_import_warns
Mar 16, 2022
Merged

Better warnings for deprecated java_import forms#7143
headius merged 1 commit intojruby:jruby-9.3from
headius:java_import_warns

Conversation

@headius
Copy link
Member

@headius headius commented Mar 16, 2022

  • import in any context: warn of deprecation, recommend
    java_import instead.
  • java_import from a non-module object: removed deprecated
    definition since it was being overwritten by toplevel
    definition and lazy import is a good use case to support.
  • java_import from toplevel: works without warning.

Fixes #6976

$ jruby -e 'java_import java.lang.System; p System'
Java::JavaLang::System

$ jruby -e 'import java.lang.System; p System'
-e:1: warning: import is deprecated; use java_import
Java::JavaLang::System

$ jruby -e 'class X; def foo; java_import java.lang.System; p System; end; end; X.new.foo'
Java::JavaLang::System

@headius headius added this to the JRuby 9.3.4.0 milestone Mar 16, 2022
@headius
Copy link
Member Author

headius commented Mar 16, 2022

This does introduce a visible change that might not be appropriate: the old logic overwrite the deprecated instance-method java_import form when defining the toplevel java_import, but now the instance-method form will warn. This may be a pattern we actually want to continue supporting, for lazily importing Java classes before first usage.

@headius headius force-pushed the java_import_warns branch from 4f624d5 to 431a297 Compare March 16, 2022 19:36
@headius
Copy link
Member Author

headius commented Mar 16, 2022

I modified this to undeprecate the instance method form of java_import since it was being overwritten by the non-deprecated toplevel java_import and we would like to continue supporting the lazy-import use case:

def foo
  java_import some.class.we.need.Now
  do something with Now
end

@headius headius changed the base branch from master to jruby-9.3 March 16, 2022 20:27
* import in any context: warn of deprecation, recommend
  java_import instead.
* java_import from a non-module object: removed deprecated
  definition since it was being overwritten by toplevel
  definition and lazy import is a good use case to support.
* java_import from toplevel: works without warning.

Fixes jruby#6976

```
$ jruby -e 'java_import java.lang.System; p System'
Java::JavaLang::System

$ jruby -e 'import java.lang.System; p System'
-e:1: warning: import is deprecated; use java_import
Java::JavaLang::System

$ jruby -e 'class X; def foo; java_import java.lang.System; p System; end; end; X.new.foo'
Java::JavaLang::System
```
@headius headius force-pushed the java_import_warns branch from 431a297 to 23a31d4 Compare March 16, 2022 20:28
@headius headius merged commit fe9f2b7 into jruby:jruby-9.3 Mar 16, 2022
@headius headius deleted the java_import_warns branch March 16, 2022 20:51
robbavey added a commit to robbavey/logstash-input-beats that referenced this pull request Apr 14, 2022
As of jruby-9.3, the use of `import` in ruby file to import java classes
has been deprecated, and the use of `java_import` is recommended.

Relates: jruby/jruby#6976,
         jruby/jruby#7143
robbavey added a commit to logstash-plugins/logstash-input-beats that referenced this pull request Apr 26, 2022
* Remove use of deprecated java `import` from ruby

As of jruby-9.3, the use of `import` in ruby file to import java classes
has been deprecated, and the use of `java_import` is recommended.

Relates: jruby/jruby#6976,
         jruby/jruby#7143
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.

[Better error/notification message] "calling java_import on a non-Module object is deprecated"

1 participant