Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PDF File corrupted exception #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sonique6784
Copy link

Hi
this fix prevent the lib to crash on RuntimeException File corrupted.
it's a basic try - catch that set cancelled to true, to cancel the process.

here is the full trace:

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.RuntimeException: PDF file is corrupted
at org.vudroid.pdfdroid.codec.PdfDocument.open(PdfDocument.java)
at org.vudroid.pdfdroid.codec.PdfDocument.openDocument(PdfDocument.java:28)
at org.vudroid.pdfdroid.codec.PdfContext.openDocument(PdfContext.java:18)
at org.vudroid.core.DecodeServiceBase.open(DecodeServiceBase.java:59)
at com.joanzapata.pdfview.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:52)
at com.joanzapata.pdfview.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:31)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)

Hi
this fix prevent the lib to crash on RuntimeException File corrupted.
it's a basic try - catch that set cancelled to true, to cancel the process.

here is the full trace:

java.lang.RuntimeException: An error occured while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:300)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.RuntimeException: PDF file is corrupted
       at org.vudroid.pdfdroid.codec.PdfDocument.open(PdfDocument.java)
       at org.vudroid.pdfdroid.codec.PdfDocument.openDocument(PdfDocument.java:28)
       at org.vudroid.pdfdroid.codec.PdfContext.openDocument(PdfContext.java:18)
       at org.vudroid.core.DecodeServiceBase.open(DecodeServiceBase.java:59)
       at com.joanzapata.pdfview.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:52)
       at com.joanzapata.pdfview.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:31)
       at android.os.AsyncTask$2.call(AsyncTask.java:288)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)
@engmonsh
Copy link

engmonsh commented May 15, 2016

@JoanZapata is there any plan to merge this pull request? I really need that handle without import library explicity into the project cc @sonique6784

@bozapro
Copy link

bozapro commented May 23, 2016

👍

@kostyabakay
Copy link

@sonique6784 thanks for your solution.

@kostyabakay
Copy link

It will be better to add showing message for user.

@Override
    protected Void doInBackground(Void... params) {
        try {
            decodeService = new DecodeServiceBase(new PdfContext());
            decodeService.setContentResolver(pdfView.getContext().getContentResolver());
            decodeService.open(uri);
        } catch (Exception e){
            // Prevent  java.lang.RuntimeException: PDF file is corrupted
            this.cancelled = true;
            showErrorMessage(e.getMessage());
        }
        return null;
    }

private void showErrorMessage(final String message) {
     Handler handler =  new Handler(pdfView.getContext().getMainLooper());
     handler.post( new Runnable(){
         public void run(){
             Toast.makeText(pdfView.getContext(), message, Toast.LENGTH_LONG).show();
         }
     });
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants