0

Google searches result in nothing, I imagine because this error is new to Java 8's new sugar. Why does NetBeans tell me "incompatible thrown types IOException in method reference" when I catch the IOException?

Screenshot of error

Screenshot of error

Full method code

/**
 * Either extracts or returns the pre-extracted language file for the given locale
 * 
 * @param locale the locale 
 * @return
 * @throws IOException 
 */
private InputStream getLanguageFile(Locale locale) throws IOException
{
    File extracted = SaveConstants.inventSaveFileFor(Main.GAME_NAME, locale.toLanguageTag() + ".lang");
    if (!extracted.exists())
    {
        InputStream in = Resources.getLanguageStream(locale);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        extracted.getParentFile().mkdirs();
        try
        {
            extracted.createNewFile();
            Writer writer = new FileWriter(extracted);
            reader
                .lines()
                .forEach(writer::write);
        }
        catch (IOException ex)
        {
            Logger.getLogger(Lang.class.getName()).log(Level.SEVERE, "Cannot extract language file for " + locale + ". Loading directly to map", ex);
            return in;
        }
    }
    else
        return new FileInputStream(extracted);
}

Note: I know it won't compile because of a missing return, but I want to get this down before I move on to the return

Ky -
  • 30,724
  • 51
  • 192
  • 308
  • @SotiriosDelimanolis Okay, I changed it to a lambda expression but now I get "unreported exception IOException; must be caught or declared to be thrown" – Ky - Sep 23 '14 at 16:14
  • What do you mean by _changed it to a lambda expression_? The error message might be misleading, but you simply can't have a method reference or lambda that doesn't match the `Consumer` functional interface. – Sotirios Delimanolis Sep 23 '14 at 16:17
  • @SotiriosDelimanolis follow-up here: https://stackoverflow.com/questions/26000017/why-is-netbeans-saying-unreported-exception-ioexception-must-be-caught-or-decl – Ky - Sep 23 '14 at 16:21

0 Answers0