Strange Java-Brew behaviour

(Blirp) #1

I code Java applications on my Mac. So I’ve installed quite a few versions over time:

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (8):
    10.0.2, x86_64:	"Java SE 10.0.2"	/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
    1.8.0_161, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home
    1.8.0_102, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home
    1.8.0_73, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home
    1.8.0_71, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_71.jdk/Contents/Home
    1.8.0_40, x86_64:	"Java SE 8"	/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
    1.7.0_80, x86_64:	"Java SE 7"	/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
    1.7.0_71, x86_64:	"Java SE 7"	/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home

Seeing Java 10 there is odd since using brew cask info java shows me I have the java cask installed. I would expect Java 11 after a brew update && brew upgrade.

But even more strange is

$ brew cask info java
java: 11.0.2,9
https://jdk.java.net/
/usr/local/Caskroom/java/1.8.0_102-b14 (227.5MB)
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/java.rb
==> Name
OpenJDK
==> Artifacts

This seems to be mixing Java 8 and Java 11 to get me Java 10?

So I thought I’d remove it all and try again:

$ brew cask remove java
Error: Cask 'java' is unreadable: undefined method `undent' for #<String:0x00007f9f4dde8c28>

Any tips on how to get Java 11 on this machine, and preferably remove all the unnecessary ones?

(Joe Wicentowski) #2

I can’t answer the larger question, but I did want to point out one thing: brew upgrade does not upgrade casks. See https://github.com/Homebrew/homebrew-cask/blob/master/USAGE.md#updatingupgrading-casks.

(Blirp) #3

Excellent! Thanks.

That first introduced a lot of new errors, like “Error: Cask ‘asepsis’ definition is invalid: Token ‘{:v1=>“asepsis”}’ in header line does not match the file name.” and after https://github.com/Homebrew/homebrew-cask/issues/23869 “Error: Cask ‘asepsis’ is unavailable: No Cask with this name exists.” and so on for several packages.
I also ended up removing a couple of packages I actually use, like Firefox and Thunderbird.

Fortunately, all of these where fixable, so I now have a more up-to-date system, and new knowledge of brew.

But Java, which brought all this on, is still wrong:

$ brew cask outdated 
java (1.8.0_102-b14) != 12.0.1,69cfe15208a647278a19ef0990eea691

Which is expected. But

$ brew cask upgrade 
==> Casks with `auto_updates` or `version :latest` will not be upgraded
==> Upgrading 1 outdated package:
Warning: Unexpected method 'license' called on Cask java.
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
Error: Cask 'java' is unreadable: undefined method `undent' for #<String:0x00007f90a84f81d0>

Cask ‘java’ is unreadable?

(Sean Molenaar) #4

I think your best guess is to reset your install using brew update-reset

(Blirp) #5

Did that, unfortunately, it didn’t help.

I think the problem is with Homebrew deleting methods. Old installs will then fail to be updated or uninstalled because the API-version they depend on, doesn’t exist anymore. IOW. I’m hitting this: https://github.com/Homebrew/homebrew-cask/issues/49716, which apparently was abandoned last August.

Manually editing java.rb way down in /usr/local/Caskroom/java/.metadata/1.8.0_102-b14/20160905083841.190/Casks to remove the call to undent seems to work.

$ /usr/libexec/java_home -V 2>&1 | head -n 2
Matching Java Virtual Machines (8):
    12.0.1, x86_64:	"OpenJDK 12.0.1"	/Library/Java/JavaVirtualMachines/openjdk-12.0.1.jdk/Contents/Home
(Sean Molenaar) #6

update-reset should have reset that to the latest version. And you’re right, homebrew works best if you update often.

(Blirp) #7

The latest version of what? Are all existing cask-files updated when core functionality is removed? That would be nice, but a huge undertaking just for removing f.x. the undent or license methods.

I do update often, but I was not aware that casks didn’t update on brew update && brew upgrade, that a separate brew cask update && brew cask upgrade was needed. And so my casks deteriorated to a state where they were useless.
My process is now updated (process update && process upgrade).

(Sean Molenaar) #8

That is what happens.

(Joe Wicentowski) #9

brew update is sufficient for updating both homebrew and caskroom. brew cask upgrade is separate from brew upgrade though. So I guess that leaves you with:

brew update && brew upgrade && brew cask upgrade