Java blobstore method completeMultipartUpload throw null pointer exception for checkNotNull - java

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.

Related

tabula asks me to update java while last version already installed

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.

R code in Java working in Linux but not in Windows

What am I doing?
I am writing a data analysis program in Java which relies on R´s arulesViz library to mine association rules.
What do I want?
My purpose is to store the rules in a String variable in Java so that I can process them later.
How does it work?
The code works using a combination of String.format and eval Java and RJava instructions respectively, being its behavior summarized as:
Given properly formatted Java data structures, creates a data frame in R.
Formats the recently created data frame into a transaction list using the arules library.
Runs the apriori algorithm with the transaction list and some necessary values passed as parameter.
Reorders the generated association rules.
Given that the association rules cannot be printed, they are written to the standard output with R´s write method, capture the output and store it in a variable. We have converted the association rules into a string variable.
We return the string.
The code is the following:
// Step 1
Rutils.rengine.eval("dataFrame <- data.frame(as.factor(c(\"Red\", \"Blue\", \"Yellow\", \"Blue\", \"Yellow\")), as.factor(c(\"Big\", \"Small\", \"Small\", \"Big\", \"Tiny\")), as.factor(c(\"Heavy\", \"Light\", \"Light\", \"Heavy\", \"Heavy\")))");
//Step 2
Rutils.rengine.eval("transList <- as(dataFrame, 'transactions')");
//Step 3
Rutils.rengine.eval(String.format("info <- apriori(transList, parameter = list(supp = %f, conf = %f, maxlen = 2))", supportThreshold, confidenceThreshold));
// Step 4
Rutils.rengine.eval("orderedRules <- sort(info, by = c('count', 'lift'), order = FALSE)");
// Step 5
REXP res = Rutils.rengine.eval("rulesAsString <- paste(capture.output(write(orderedRules, file = stdout(), sep = ',', quote = TRUE, row.names = FALSE, col.names = FALSE)), collapse='\n')");
// Step 6
return res.asString().replaceAll("'", "");
What´s wrong?
Running the code in Linux Will work perfectly, but when I try to run it in Windows, I get the following error referring to the return line:
Exception in thread "main" java.lang.NullPointerException
This is a common error I have whenever the R code generates a null result and passes it to Java. There´s no way to syntax check the R code inside Java, so whenever it´s wrong, this error message appears.
However, when I run the R code in brackets in the R command line in Windows, it works flawlessly, so both the syntax and the data flow are OK.
Technical information
In Linux, I am using R with OpenJDK 10.
In Windows, I am currently using Oracle´s latest JDK release, but trying to run the program with OpenJDK 12 for Windows does not solve anything.
Everything is 64 bits.
The IDE used in both operating systems is IntelliJ IDEA 2019.
Screenshots
Linux run configuration:
Windows run configuration:

R java io unchecked io exception error

I am running R studio with R version 3.4.1 and java version 1.8.0_131
I am trying to run a function I created and I am getting these errors:
I get this error when I run the specific function
java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
I get this error when I run the entire script
Error in ._jobjRef_dollar(x[["jobj"]], name) :
no field, method or inner class called '.when'
I am wondering if anyone may have an idea as to what is causing these errors, before I post the function. It is pretty long. It is essentially opening multiple files and reading them as tables. Each path is correct and it works individually.
It looks like you are trying to use .when somewhere in your script, however there is no such method for .when.
The issue could be that one of your libraries (R?) is an older version than the documentation you are using, or the .when call never existed in the first place.
The easiest way to fix this is to search and find out where .when is being called in your code, and then check if there is another method you can use instead, or if you just need to update to a newer library.
Add a bit of debugging code to print to console between opening each file and between reading them to the tables, that way you can at least see how far along your code gets before it fails.
For reference on where the error is called, you can take a look at the source for rJava here:
https://github.com/cran/rJava/blob/master/R/reflection.R
Specifically note your error in the last else block when rJave attempts to look for a function, but cannot find it:
### syntactic sugar to allow object$field and object$methods(...)
### first attempts to find a field of that name and then a method
._jobjRef_dollar <- function(x, name) {
if (hasField(x, name) ){
.jfield(x, , name)
} else if( hasJavaMethod( x, name ) ) {
function(...) .jrcall(x, name, ...)
} else if( hasClass(x, name) ) {
cl <- .jcall( x, "Ljava/lang/Class;", "getClass" )
inner.cl <- .jcall( "RJavaTools", "Ljava/lang/Class;", "getClass", cl, name, FALSE )
new("jclassName", name=.jcall(inner.cl, "S", "getName"), jobj=inner.cl)
} else if( is.character(name) && length(name) == 1L && name == "length" && isJavaArray(x) ){
length( x )
} else {
stop( sprintf( "no field, method or inner class called '%s' ", name ) )
}
}

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