java.lang.NoSuchMethodError while switching from owl-api 3.5 to 4.x - nosuchmethoderror

I've used the owl-api version 3.5 and now I would like to switch to Version 4, but I get a runtime exception. Like in the following example code (which works fine with version 3.5) a java.lang.NoSuchMethodError it thrown every time invoking the function "manager.addAxiom(...)".
WLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://example.com/owlapi/families");
OWLOntology ont = manager.createOntology(ontologyIRI);
OWLDataFactory factory = manager.getOWLDataFactory();
OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLIndividual mary = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#Mary"));
OWLObjectProperty hasWife = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasWife"));
OWLObjectPropertyAssertionAxiom axiom1 = factory.getOWLObjectPropertyAssertionAxiom(hasWife, john, mary);
manager.addAxiom(ont, axiom1);
...
The whole exeption which is thrown says:
Exception in thread "main" java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLOntologyManager.addAxiom(Lorg/semanticweb/owlapi/model/OWLOntology;Lorg/semanticweb/owlapi/model/OWLAxiom;)Lorg/semanticweb/owlapi/model/parameters/ChangeApplied;
at de.ifak.Writer.OWL.Example.OWLMinimalTest.main(OWLMinimalTest.java:26)
I've tested the code in a clean Java project and added the owl-api dependencies manual and later with maven. I've testet it with version 4.0.2 and 4.1.0-RC2. Both have shown the same behavior.
I couldn't find any solution for that. So I hope someone can help me.
Thanks,
Chris

Ok, I found a solution by myself.
If I change the code
manager.addAxiom(ont, axiom1);
to
Set<OWLAxiom> axiomsToAdd = new HashSet<OWLAxiom>();
axiomsToAdd.add(axiom1);
manager.addAxioms(ont, axiomsToAdd);
all works fine, even with version 4.1 of the owl-api.
Edit:
Ok I made a mistake. It works fine with version 4.0.2 but with version 4.1 I get the same exception when I call:
manager.addAxioms(ont, axiomsToAdd);
like when I call:
manager.addAxiom(ont, axiom1);

The addAxiom method is still there but its return type has changed. Are you assigning the value returned to a variable?

Related

ConsoleLauncher returns 0 although class-under-test could not be loaded

We run a set of tests in a CI pipeline and call our test classes like this:
java -classpath junit-jupiter-api-5.0.1.jar:junit-platform-console-standalone-1.0.1.jar org.junit.platform.console.ConsoleLauncher --select-class xy.Test
If class xy.Test cannot be found on the classpath an error message appears but ConsoleLauncher's return value is 0! Since our CI system runs unattended the return value is the only important return value!
As I have seen this behaviour got updated in JUnit 5.0.0 M2 but I regard this as I mistake: If I define a class by --select-class and the class cannot be found then something has gone wrong!
As I countermeasure I hacked (by means of introspection) org.junit.platform.commons.util.BlacklistedExceptions by overwriting blacklist's field with OutOfMemoryError (=default) and PreconditionViolationException (=case where class could not be found).
(If the standard behaviour shall not be changed...) I think there should be a better way to get this behaviour!

a session error after updating to laravel 5.4

After updating from laravel 5.3 to 5.4, I encountered an error in vendor. The error is:
Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Illuminate\Session\Store::set() in /var/www/ostadbank.com/vendor/laravel/framework/src/Illuminate/Support/Manager.php:137
But when I go to my error is:
fatal error exception in Manager.php line 137:call to undefined method Illuminate\session\store::set()
I go to manager.php line 137 and I see the line below:
public function __call($method, $parameters) { return $this->driver()->$method(...$parameters); }
I am not sure where to start to modify.
See the screenshots below:
I solve it, for more information read this: https://laravel.com/docs/5.4/upgrade
All calls to the ->set() method should be changed to ->put(). Typically, Laravel applications would never call the set method since it has never been documented within the Laravel documentation. However, it is included here out of caution.

MySql with Slick 3.0 giving "No suitable driver"

I'm trying to get Slick 3.0 running with MySql. I've made the following changes to the hello-slick-3.0 activator project:
In application.conf I've removed the h2mem1 entry and replaced it with:
horridDBStuff = {
url = "utterlyhorriddb.blahblahblah.us-west-2.rds.amazonaws.com:3306"
driver = com.mysql.jdbc.Driver
connectionPool = disabled
keepAliveConnection = true
}
I've replaced each Database.forConfig("h2mem1") entry in the scala
code with Database.forConfig("horridDBStuff")
I've replaced each import slick.driver.H2Driver.api._ with
import slick.driver.MySQLDriver.api._
In build.sbt I've added to libraryDependencies the item
"mysql" % "mysql-connector-java" % "5.1.35"
It compiles fine, but running gives the error Exception in thread "main" java.sql.SQLException: No suitable driver coming from the line val db = Database.forConfig("horridDBStuff").
How can I get Slick 3.0 running with MySql? Am I missing something simple here, or are there any other working examples? Thanks.
Fixed it. The URL in application.conf was in the wrong format. Should be
url = "jdbc:mysql://utterlyhorriddb.blahblah.us-west-2.rds.amazonaws.com/aardvark_schema"
where you've already created ardvark_schema in your database.
(That fixes the db access issue that I was asking about, but you'll still get a key-spec error. To fix that you need to remove the O.PrimaryKey entry from Tables.scala for "COF_NAME", which is described here: How to get around Slick 3.0 schema creation getting errors due to key specs without length.)

write_rich_text of xlwt returns error

I am using xlwt and the following code returns the error Worksheet object has no attribute write_rich_text Why would that be?
seg1 = ("NOT ", Font1)
seg2 = (str(data['Customer'])[:-1], Font2)
sheet1.write_rich_text(row, 4, (seg1, seg2) , Style1)
Note: I am using xlwt 0.7.5 and I see write_rich_text() defined in worksheet.py file
How are you initializing your sheet1 variable?
Make sure there is a page first:
wb = xlwt.Workbook()
sheet1 = wb.add_sheet('Sheet1')
sheet1.write_rich_text(....)
Also you want to take into consideration that write_rich_text is not included in all versions of xlwt so you might want to make sure that the version of xlwt that you are using is the same version that you verified that actually has write_rich_text. Clearly the version that is imported into your app doesn't know anything about a write_rich_text method.
Thank you Max for the pointer. Yes, I had an older version of xlwt in python27 that didn't have write_rich_text method. Replacing that xlwt with the newer version fixed the issue.

NUnit / Moq throwing a NullReferenceException error on the constructor of a variable

I am using Moq, NUnit, WPF, MVVM, Ninject.
I am writing a test for my LoginViewModel, and in the test when I use the constructor of the LoginViewModel to create a new instance, I am getting a NullReferenceException error. The code compiles and runs, (i.e. when I run the program the LoginView shows, and works with the LoginViewModel to create the correct behaviour etc) but for some reason the UnitTest is crashing.
this is the constructor:
public LoginViewModel(ILoginServices loginServices,IDialogService dialogServices)
{
InitializeFields();
_loginServices = loginServices;
_dialogService = dialogServices;
DomainList = _loginServices.GetDomainListing();
}
I have mocked the dependencies as follows:
Mock<ILoginServices> moq = new Mock<ILoginServices>();
moq.Setup(log =>
log.LoginUser(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<string>()))
.Callback<string, string, string>((i, j, k) => CheckArgs(i, j, k));
moq.Setup(log2 =>
log2.GetDomainListing()).Returns(new List<string> { "Domain" });
Mock<IDialogService> moq2 = new Mock<IDialogService>();
I have also tried inserting real services as the parameters.
I have verified that the mocks do work, and the objects these mocks
return are not null.
I have commented out all the code in the constructor.
I have tried inserting the line
LoginViewModel test = new LoginViewModel(_fakeLoginService,_fakeDialogService);
in front of the call to the constructor (to see if it had to do with the original local variable being disposed or something before) and this line crashed instead.
From all I can see this must be the constructor,(but not the code I have written inside it) and that this is solely related to NUnit / Moq as my code still compiles and runs fine.
I have no idea on this one guys, can anyone point me in the right direction?
[Edit]
Ok so I have run through the code and the error comes from this line of code:
ImageSource = (ImageSource)Application.Current.FindResource(_imageName);
This code is going to a ImageDictionary and getting a reference to the image for an undo button in the WindowViewModel (which my LoginViewModel inherits).
My hypotheses as to why its working in the normal running of the application, but not in the testing are:
1) Because I am running the program code through NUnit, the Application.Current object isnt getting property assigned/there is no Application.Current object to get.
**or**
2) Something to do with the fact that because the program code is being run in NUnit, the code doesn't have access to/can't resolve the ImageDictionary to find the image.
I'm leaning more strongly to the first hypothesis, but I'm as of yet not 100% sure, and I am having trouble finding the values of the Application.Current at runtime, cause when I move my cursor over the code the tooltip that normally appears showing the detail of the object that is not appearing.
My new question is: Does any of this make sense? Do you guys know if the Application.Current object exists / can be accessed when running the testing project through NUnit?
Any help will be appreciated.
You are correct. Application.Current is null for Unit tests. You can work around this by injecting the Application object as referencing singletons in code can make life tricky.