Skip to content
  • Categories
Collapse
Solibri Society Forum
  1. Home
  2. General Discussion
  3. NullPointerException

NullPointerException

Scheduled Pinned Locked Moved General Discussion
3 Posts 2 Posters 500 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paulinasta
    wrote on last edited by paulinasta
    #1

    Hi everyone,

    As mentioned before, I’m a complete beginner, so any advice is greatly appreciated. 🙂

    I wrote a simple rule:

    package com.solibri.rule;
    import java.text.MessageFormat;
    import java.util.Collection;
    import java.util.Collections;
    import com.solibri.smc.api.checking.IntParameter;
    import com.solibri.smc.api.checking.OneByOneRule;
    import com.solibri.smc.api.checking.Result;
    import com.solibri.smc.api.checking.ResultFactory;
    import com.solibri.smc.api.checking.RuleParameters;
    import com.solibri.smc.api.checking.StringParameter;
    import com.solibri.smc.api.model.Component;
    import com.solibri.smc.api.model.components.Space;
    import com.solibri.smc.api.model.components.Window;
    
    public class NumberOfWindowsInSpace2 extends OneByOneRule {
    	
    	private final RuleParameters params = RuleParameters.of(this);
    	final IntParameter minimumAmountOfWindows = params.createInt("MinAmount");
    	final StringParameter resultNameStringParameter = params.createString("ResultName");
    
    	@Override
    	public Collection<Result> check(Component component, ResultFactory resultFactory) {
    
    		if (!(component instanceof Space)) {
    			
    			return null;
    		}
    		
    		Space space = (Space) component;
    		Collection<Window> windows = space.getWindows();
    		int amountOfWindows = windows.size();
    
    		int minimumAllowedAmount = minimumAmountOfWindows.getValue();
    
    		if (amountOfWindows >= minimumAllowedAmount) {
    			return Collections.emptyList();
    		}
    
    		String resultName = resultNameStringParameter.getValue();
    		String resultDescription = MessageFormat
    			.format("The amount of windows in space {0} is less than allowed.",
    				component.getName());
    
    		Result result = resultFactory.create(resultName, resultDescription);
    		return Collections.singleton(result);
    	}
    }
    

    But I keep getting the same error in Solibri:

    Please send this error message and application information to [email protected] (see File->Help). 
    Error Message: java.lang.NullPointerException: Cannot invoke "java.util.Collection.isEmpty()" because " " is null 
    at com.solibri.smc.api.checking.OneByOneRule.a(Unknown Source) 
    at java.basejava.lang.Iterable.forEach(Iterable.java:75) 
    at com.solibri.smc.api.checking.OneByOneRule.check(Unknown Source)
    at com.solibri.saf.plugins.checkingplugin.rule.RuleSerializedState.check(Unknown Source) 
    at com.solibri.sae.greenox.Constraint.d(Unknown Source) 
    at com.solibri.sae.greenox.Constraint.runCheck(Unknown Source) 
    at com.solibri.saf.plugins.checkingplugin.ui.CheckingViewPanel$CheckTask.compute(Unknown Source) 
    at com.solibri.saf.plugins.checkingplugin.ui.CheckingViewPanel$CheckTask.compute(Unknown Source) 
    at java.base/java.util.concurrent.RecursiveTask.exec(RecursiveTask.java:95) 
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) 
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016) 
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665) 
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598) 
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
    

    After model checking. Could anyone explain what’s wrong with the code? Thanks!

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hlg
      wrote on last edited by hlg
      #2

      @paulinasta said in NullPointerException:

         if (!(component instanceof Space)) {
        	return null;
        }
      

      I guess this is making problems downstream.
      You may want to return an empty list instead of null (like you do when amountOfWindows >= minimumAllowedAmount). The code that calls the OneByOneRule.check method tries to iterate over the result, with null that fails as you see.

      P 1 Reply Last reply
      0
      • P Offline
        P Offline
        paulinasta
        replied to hlg on last edited by
        #3

        @hlg thanks, did this before, but turns out the rules didn’t update in Solibri 🙂 it was the problem indeed 🙂

        1 Reply Last reply
        0

        Copyright © 2025 Solibri Inc. | Powered by NodeBB

        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories