Morph
Morph

Reputation: 173

Got "undefined method `[]' for nil:NilClass" installing java Cookbook

I try to set up a vagrant vm using Chef Solo and Berkshelf. I want to use the maven cookbook. "maven" depends on "java" and "java_ark" (which is included in the "java" cookbook). All of them were created by Opscode.

But everytime I get this error:

NoMethodError

-------------

undefined method `[]' for nil:NilClass




Cookbook Trace:
---------------
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/java/recipes/default.rb:21:in `from_file'
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/platform-slayer/recipes/slayer_worker.rb:2:in `from_file'


Relevant File Content:
----------------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/java/recipes/default.rb:

 14:  # Unless required by applicable law or agreed to in writing, software
 15:  # distributed under the License is distributed on an "AS IS" BASIS,
 16:  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 17:  # See the License for the specific language governing permissions and
 18:  # limitations under the License.
 19:  #
 20:  
 21>> include_recipe "java::#{node['java']['install_flavor']}"
 22:  
 23:  # Purge the deprecated Sun Java packages if remove_deprecated_packages is true
 24:  %w[sun-java6-jdk sun-java6-bin sun-java6-jre].each do |pkg|
 25:    package pkg do
 26:      action :purge
 27:      only_if { node['java']['remove_deprecated_packages'] }
 28:    end
 29:  end
 30:

Does anyone know this issue? Let me know if you need anymore information.

Upvotes: 2

Views: 3486

Answers (2)

Gustavo Matias
Gustavo Matias

Reputation: 3608

This definitely looks like a bug. For those having similar issues I suggest just use java::openjdk.

Upvotes: 0

Stephen C
Stephen C

Reputation: 718798

I think the problem is that node['java'] is evaluating to nil.

One possible solution is to define the attribute node['java']['install_flavor'] either in a cookbook or in your Node definition or a relevant Role definition.

But it looks like a bug in the cookbook, because the documentation says a default should apply to the install_flavor attribute.

Upvotes: 5

Related Questions