tabula asks me to update java while last version already installed - java

I have been testing my code a few times and it worked well every time, but now for some reason it raises a weird error that I will right down just after.
I am using tabula to read some pdf file, here is the code where it appears there is an error :
for it_page,page in enumerate(pages_id, start=0):
print("page : ", page)
tables = tabula.read_pdf(hermes_pdf_dir + "/" + pdf_name, pages = page)
for i,table in enumerate(tables, start=1):
print( "titre retenu : " + pages_id_titres[it_page][1] + f"_{i}.xlsx")
table.to_excel(os.path.join(folder_name, pages_id_titres[it_page][1] + " p" + str(page) + f"_{i}.xlsx"), index=False)
The error is at the line beginning with "tables = tabula.read_pdf(...)".
Most importantly, here is the full error message :
Traceback (most recent call last):
File "get_pdfs_hermes.py", line 299, in <module>
read_pdf_download_csv(pdf_name2)
File "get_pdfs_hermes.py", line 199, in read_pdf_download_csv
tables = tabula.read_pdf(hermes_pdf_dir + "/" + pdf_name, pages = page)
File "C:\Users\virgi\Python\lib\site-packages\tabula\io.py", line 322, in read_pdf
output = _run(java_options, kwargs, path, encoding)
File "C:\Users\virgi\Python\lib\site-packages\tabula\io.py", line 80, in _run
result = subprocess.run(
File "C:\Users\virgi\Python\lib\subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['java', '-Dfile.encoding=UTF8', '-jar', 'C:\\Users\\virgi\\Python\\lib\\site-packages\\tabula\\tabula-1.0.4-jar-with-dependencies.jar', '--pages', '104', '--guess', '--format', 'JSON', 'C:\\Users\\virgi\\Desktop\\virgile_stuff\\prog\\banking analyst\\financial_data/data/hermes_data/hermes_2014_rapportannuel_en.pdf']' returned non-zero exit status 1.
It talks about java dependencies (maybe because tabula has tabula-py and tabula-java ?) and the most related issues I found regarding this kind of errors say that java should be updated, while I have the very latest version on my computer.
Any ideas of what it could be ?

By simply making an exception for the pdf file that was tackled while the error occured, it seems to work well again. I think the issue comes from the page encodage or something like that.

Related

Java blobstore method completeMultipartUpload throw null pointer exception for checkNotNull

I have a problem with saving .csv files by multi parts. In this part of the code:
#Override
public String completeMultipartUpload(MultipartUpload mpu, List<MultipartPart> parts) {
ImmutableList.Builder<Blob> blobs = ImmutableList.builder();
long contentLength = 0;
Hasher md5Hasher = Hashing.md5().newHasher();
for (MultipartPart part : parts) {
Blob blobPart = getBlob(mpu.containerName(), MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-" + part.partNumber());
contentLength += blobPart.getMetadata().getContentMetadata().getContentLength();
blobs.add(blobPart);
md5Hasher.putBytes(BaseEncoding.base16().lowerCase().decode(blobPart.getMetadata().getETag()));
}
The problem occurs on my computer, the program works for other people. Namely, for a given part of the code, blobPart.getMetadata().GetETag() always for the first 9 parts work fine. And for part 10 and each subsequent part does return a null value for ETag, which then causes an error NullPointerException.
All List<MultipartPart> parts are adding in the same way. All have correct property.
I think it is problem with my Environment. I tried:
reinstall IntelliJ
reinstall Java/use a different version
remove all libraries and install again
Or maybe something with encoding?
Other people for which it works are from another country, and I can see there is BaseEncoding.base16()?
StackTrace:
java.lang.NullPointerException: null
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:878)
at com.google.common.io.BaseEncoding$StandardBaseEncoding.trimTrailingPadding(BaseEncoding.java:676)
at com.google.common.io.BaseEncoding.decodeChecked(BaseEncoding.java:231)
at com.google.common.io.BaseEncoding.decode(BaseEncoding.java:217)
at org.jclouds.blobstore.config.LocalBlobStore.completeMultipartUpload(LocalBlobStore.java:843)
I hit perfectly the limit of the path length for windows, it threw an error because the path passed to
UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(file.toPath()); it was too long.

An error occurred while performing the 'for' loop using Rserve

I execute my R code in Rstudio,and it worked well.The following pitcute shows how my R code work.
enter image description here
And then,I want to execute my R code using Java through Rserve.The following code is my Java code:
c.eval("kandweight=kand(person)");
c.eval("person");
c.eval("system=c(3,6,5,9,2)");
c.eval("systemw=matrix(,length(system))");
c.eval("k=0");
c.eval( "for(i in 1:length(system))"
+ "{"
+ "j=sum(system[1:i])"
+ "systemw[i]=sum(indexw[1:j])-k"
+ "k=sum(systemw[1:i])"
+ "}");
cin my Java code is Rserve connection.And I got an error.The error shows that the linec.eval( "for(i in 1:length(system))"eval failed.I am still trying to fix this but need some outside help. Many thanks.
I guess it would become valid if you separate the lines with semicolons, as one would do in R if putting several commands on a single line:
c.eval("for(i in 1:length(system))"
+ "{"
+ "j=sum(system[1:i]);"
+ "systemw[i]=sum(indexw[1:j])-k;"
+ "k=sum(systemw[1:i])"
+ "}");

python tarfile.py "file could not be opened successfully"

I have a tarball that I can't open using python:
>>> import tarfile
>>> tarfile.open('/tmp/bad.tar.gz')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "tarfile.py", line 1672, in open
raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully
but I'm able to extract the file with no problem on the command line.
$ tar -xzvf /tmp/bad.tar.gz
I've traced the python tarfile code, and there's a function "nti" where they're converting bytes. It gets to this line:
obj.uid = nti(buf[108:116])
and blows up. These bits (for the UID) coming through as eight spaces. Not sure where to go from here...
Honestly it looks like the bug is in tarfile.py's nti function:
n = int(nts(s) or "0", 8)
The fall-through logic (or "0") is not working because s is spaces, not None, so int() blows up.
I copied tarfile.py from /var/lib/python2.7/ and wrapped that particular line with a try/catch, which fixed me up:
try:
obj.uid = nti(buf[108:116])
except InvalidHeaderError:
obj.uid = 0
It's a hack solution, though. Really I'd prefer that the python folk took a look at it and fixed the "or "0" logic.
Update
Turns out the tarball was created by the maven-assembly-plugin in a Java 6 project that had just been upgraded to Java 7. The issue was resolved by upgrading the maven-assembly-plugin to 2.5.3.

NullPointerException on return new[]

I have a very strange problem with NullPointerException. Code example is as follows:
...
... public String[] getParams(...) {
... ...
... ...
143 return new String[] {
144 getUserFullName(),
145 StringUtil.formatDate(sent),
. tiltu,
. StringUtil.initCap(user.getName()),
. vuosi.toString(),
. asiatyyppi[0] + " " + lisatiedot[0],
. asiatyyppi[1] + " " + lisatiedot[1],
. alaviitteet[0],
152 alaviitteet[1]};
153 }
Now, I have got an issue from production having a stack trace:
java.lang.NullPointerException
at package.EmailService.getParams(EmailService.java:143)
...
I am unable to produce that kind of stack trace myself. It maybe some environment issue that for some reason line numbers don't match. If I have null references on any variable stack trace points to that specific line but never to line 143.
But what I want to ask is: is it possible to produce NullPointerException at line 143 specifically?
The line number in the stack trace comes from the LineNumberTable attribute in the class file. (See JVM specification)
It would be no problem to output the right line number for a subexpression - all the compiler has to do is to say that from byte-code index x to y, there is a correspondence with source code line z.
But up to and including Java 1.7 there was a bug in the compiler, that was fixed in 1.8:
https://bugs.openjdk.java.net/browse/JDK-7024096
A DESCRIPTION OF THE PROBLEM : linenumbertable in compiled code only
has line numbers for starts of statements. When a statement is using
method chaining or other "fluent Interface" style API's a single
statement can span tens of lines and contain hundreds on method
invocations.
Currently an exception throw from within any of these methods will
have the linenumber of the first line of the enclosing statement which
makes it very hard to debug which method call is having a problem.
linnumbertable should have correct line numbers for every method
invocation.
--
BT2:EVALUATION
It seems simple enough to fix this, but its kinda risky at the end of
the jdk7 development cycle, targetting to jdk8.
So in 1.7, you would get the wrong reported line number for these kind of subexpressions (if they occurred within the same method though - if you invoked another method in a subexpression, and that other method caused a NullPointerException, you would see it reported there - this is probably why the bug isn't always a big problem)
One way you could work around this is by taking the Java 8 compiler to compile your source code, and use the flags javac -source 1.7 -target 1.7. But it would be better and safer to upgrade your prod environment to 1.8.
Consider your original code which defines a new String array:
return new String[] {
getUserFullName(),
StringUtil.formatDate(sent),
tiltu,
StringUtil.initCap(user.getName()),
vuosi.toString(),
asiatyyppi[0] + " " + lisatiedot[0],
asiatyyppi[1] + " " + lisatiedot[1],
alaviitteet[0],
alaviitteet[1]};
}
If any of the elements of the inline array should trigger a NullPointerException the JVM will interpret the Exception as having occurred on the line where the definition began. In other words, the JVM will view the above code as being the same as:
return new String[] { getUserFullName(), StringUtil.formatDate(sent), tiltu, StringUtil.initCap user.getName()), vuosi.toString(), asiatyyppi[0] + " " + lisatiedot[0], asiatyyppi[1] + " " + lisatiedot[1], alaviitteet[0], alaviitteet[1]}; }
where everything is on one line.
If you really want to handle NullPointerExceptions here, you should define the variables outside the instantiaition.

Get history of a Deleted File from SVN using SVNKit

I am trying to access Revision History of a file that has been deleted using SVNKit.
Following is what I am doing to achieve that.
SVNClientManager manager = SVNClientManager.newInstance();
SVNLogClient logClient = manager.getLogClient();
logClient.doLog(svnURL, new String[] { fileName }, SVNRevision.create(deletedRevision),
SVNRevision.UNDEFINED, SVNRevision.UNDEFINED, false, false, true, -1, null,
new ISVNLogEntryHandler() {
public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
log.debug(" ==== " + logEntry.getChangedPaths() + " === "
+ logEntry.getRevision());
}
});
Here, deletedRevision => The SVN revision in which File was deleted.
When this code is executed I keep on getting following exceptions:
org.tmatesoft.svn.core.SVNException: svn: '<FilePath>' path not found: 404 Not Found (https://<RepositoryURL>
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:64)
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:51)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.logImpl(DAVRepository.java:976)
at org.tmatesoft.svn.core.io.SVNRepository.log(SVNRepository.java:1034)
at org.tmatesoft.svn.core.wc.SVNLogClient.doLog(SVNLogClient.java:1024)
at org.tmatesoft.svn.core.wc.SVNLogClient.doLog(SVNLogClient.java:891)
at com.blueoptima.connectors.scr.SVN.getWorkingFileList(SVN.java:711)
... 4 more
Is it something that I am doing wrong here? Is there any other way to get the History of a deleted file using SVNKit
Though this question has been asked more than a year back but still thought of answering it if it could be other's help.
I didnt try for retrieving history of a deleted file but i could retrieve the history of a deleted branch using -
SVNLogClient.doLog(SVNURL.parseURIEncoded(path), new String[] { "" }, pegRevision, SVNRevision.create(0),pegRevision, stopOnCopy, discoverChangedPaths, logsLimit, logHandler);
This is similar to the call you are making but you need to supply proper values for pegRevision, startRevision and endRevision. Use of UNDEFINED may not give correct result, instead use the revision at which file was deleted as pegRevision and startRevision as 0 and it should work.
You should specify a revision where the file existed as a peg revision. Obviously it is deletedRevision-1. And maybe (I'm not sure here, just try) the file should exist in both start and end revisions.

Categories

Resources