Closed cici-debug closed 4 years ago
@cici-debug can you give a full minimized example to reproduce it?
I used an customized adapter and the database is empty.
MyAdapter a = new MyAdapter();
Enforcer e = new Enforcer("examples/rbac_model.conf", a);
e.addPolicy("alice", "data", "query")
I found that the problems happened because of this line: https://github.com/casbin/jcasbin/blob/7dc03b642b571ff5d71b96188bc2621ff059dcf2/src/main/java/org/casbin/jcasbin/model/Policy.java#L118
Then your adapter causes this crash. @tldyl please follow up this issue.
Acutally we make sure our official code is correct. If you added your custom code, please see if you have bugs in your own code.
If i do not use the adpter, just new the enforcer this way:
Enforcer enforcer = new Enforcer("./src/main/resources/model.conf", "./src/main/resources/policy.conf"); enforcer.getPolicy();
NullPointerException was also throw. The policy file is an empty file btw. It is not my adapter causing the crash.
@cici-debug please review this fix: https://github.com/casbin/jcasbin/pull/95
That's my config file that caused the problem. I will close the issue. Thanks for the help.
Member functions of Policy class do not check if the key
ptype
exists in the map, so when I tried to callenforcer.addPolicy()
orenforcer.getPolicy()
after init enforcer with empty policy, NullPointerException was throw. Is it a design issue? Ptype's existence should be checked and if it does not exist, empty list should be returned, not NullPointerException.